【问题标题】:Why reCaptcha don't work on my wordpress comments template为什么 reCaptcha 不适用于我的 wordpress 评论模板
【发布时间】: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”,但只将我重定向到一个空页面。 我应该使用哪个正确的操作?

【问题讨论】:

  • 请仅显示与您的问题相关的代码。不需要把整个表格放在这里。
  • 谢谢,现在只有相关代码了。

标签: php wordpress recaptcha


【解决方案1】:

我发现了错误:

$response = recaptcha_check_answer (...);//<- ?!!

if (!$resp->is_valid) {

首先变量被称为$response,然后是$resp

【讨论】:

  • 谢谢,我已更改此错误,但这并不能解决我的问题。
  • @evega 为什么将表单操作更改为“wp-cmets-post.php”?现在你正确的 verify.php 没有被激活。切换回验证或添加验证码到wp-cmets-post.php。
  • 好的,谢谢,经过多次更改,我已经疯了。所以我推断正确的表单动作是verify.php?但是通过此操作,当我提交评论时,总是被重定向到带有 de URL 的空白页面:“myweb.com/verify.php
  • 那么,在成功的验证动作中我应该执行“wp-cmets-post.php”动作吗?
  • @evega 这很难,因为你必须从 verify.php 中调用 wp-cmetss-post 中的函数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-31
  • 2013-03-21
相关资源
最近更新 更多