【发布时间】:2018-04-12 10:52:31
【问题描述】:
我正在尝试在受密码保护的页面上显示的表单上实施 reCaptcha 验证。我尝试了不同的插件,但在受密码保护的页面上没有显示选项。 我找到了一种在页面上显示 reCaptcha 字段的方法,其中包含我在主题文件夹的 functions.php 文件中添加的自定义表单功能。但我不知道如何在提交信息之前验证 reCaptcha。
function my_custom_js() {
echo '
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("form1").submit();
}
</script>';
}
add_action('wp_head', 'my_custom_js');
add_filter( 'the_password_form', 'custom_password_form' );
function custom_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form class="protected-post-form" id="form1" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post" >
' . __( "This is a password protected page. Please enter the password below:" ) . '
<label class="pass-label" for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" />
<input type="submit" name="Submit" class="button" value="' . esc_attr__( "Submit" ) . '" />
<button
class="g-recaptcha button"
data-sitekey="6Ld2wVIUAAAAAPnw70ZMDA9Auxu_Tl1rqV-W4kxv"
data-callback="onSubmit">
Submit
</button>
</form>
';
return $o;
}
我还收到一条错误消息:
Invalid reCAPTCHA client id: null
at Object.Cr [as reset] (recaptcha__en.js:391)
at (index):1158
at wp_recaptchaLoadCallback ((index):1160)
at recaptcha__en.js:394
at ir (recaptcha__en.js:378)
at recaptcha__en.js:394
at recaptcha__en.js:405
我被困住了。我不知道下一步该怎么做。 谢谢您阅读此篇。如果有人能指出我正确的方向,那对我来说就意味着整个世界。
【问题讨论】: