【发布时间】:2018-04-15 10:52:41
【问题描述】:
我试图在我的第一个 wordpress 主题的 cmets 中避免垃圾邮件,问题是我已经关注了所有 Google PHP API instructions,并且它显示完美,但验证出错了,我想是因为我可以发布 cmets 在 recaptcha 中输入错误的单词。
利用这个问题,我也想知道如何将返回的错误消息与提交按钮放在一起。
这是 cmets.php 表单片段:
<form class="comments-form" action="verify.php" method="post" id="commentform">
...
<?php
require_once('recaptchalib.php');
$publickey = "my_pulic_key";
echo recaptcha_get_html($publickey, $error);
?>
<p>
<input type="submit" name="submit" id="submit" tabindex="5" value="Enviar" />
<label for="submit"><?php echo $error ?></label>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
这是 verify.php 代码:
<?php
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //clave privada
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$error = $resp->error;
} else {
// Your code here to handle a successful verification
echo "¡Recaptcha correcto!";
//do_action("wp-comment-post.php");??????I DON´T KNOW IF THIS IS OK.
}
?>
编辑:我尝试过使用表单操作“verify.php”,但只将我重定向到一个空页面。 我应该使用哪个正确的操作?
【问题讨论】:
-
请仅显示与您的问题相关的代码。不需要把整个表格放在这里。
-
谢谢,现在只有相关代码了。