我一直在多个站点使用 Recaptcha。使用现有的 Recaptcha v2 安装,我在域列表中添加了一个新主机。随后,我确保使用了该库
<script src='https://www.google.com/recaptcha/api.js'></script>
此外,我已将必要的 reCaptcha2 标签包含到我的注册表结构模板中
public static function Registration($params) {
$response = $params["Response"];
$response->set("template",
'<label for="username">Felhasználónév</label>'.
'<input class="form-data" name="Username" type="text" id="username">'.
'<label for="password">Jelszó</label>'.
'<input class="form-data" name="Password" type="password" id="password">'.
'<label for="confirm-password">Jelszó ismétlése</label>'.
'<input class="form-data" name="ConfirmP" type="password" id="confirm-password">'.
'<label for="name">Név</label>'.
'<input class="form-data" name="Name" type="text" id="name">'.
'<label for="email">Email</label>'.
'<input class="form-data" name="Email" type="text" id="email">'.
'<label for="bio">Bio</label>'.
'<textarea class="form-data" name="Bio" id="bio"></textarea>'.
'<form><div class="g-recaptcha" id="recaptcha" data-sitekey="<my key>"></div></form>'.
'<span class="api form" data-form-name="Registration" data-events="click" data-container="#popup-content">Beküldés</span>'
);
return $response;
}
尽管在较旧的实例中使用相同的 key 是有效的,但这本身并不足以让我的 reCaptcha 显示出来。 reCaptcha 在激活之前需要一些时间吗?或者是否需要包含一些依赖项,例如 jquery?基本上,我应该怎么做才能让我的 reCaptcha 出现在我的注册面板上? (其他一切都成功出现)
最佳答案
问题是我在页面加载后在弹出窗口中动态添加了我的验证码。解决方案是将此 block 放入回调中:
var recaptcha = radWindow.querySelector("#recaptcha");
if (recaptcha) {
grecaptcha.render("recaptcha");
}
其中 radWindow
是弹出窗口对象,recaptcha
是 recaptcha 标签的 id。
关于php - 为什么 Recaptcha 没有出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47124084/