【问题标题】:how to add Captcha to my custom form in Wordpress without plugin?如何在没有插件的情况下将验证码添加到 Wordpress 中的自定义表单?
【发布时间】:2014-02-26 13:09:42
【问题描述】:

有什么方法可以将验证码添加到我在 WordPress 中的自定义表单中,我已经使用了一些插件,但它只允许在登录、评论表单等中添加验证码。

我用过 Google reCaptcha,我用过这个脚本

<script type="text/javascript"
       src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
    </script>
    <noscript>
       <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
           height="300" width="500" frameborder="0"></iframe><br>
       <textarea name="recaptcha_challenge_field" rows="3" cols="40">
       </textarea>
       <input type="hidden" name="recaptcha_response_field"
           value="manual_challenge">
    </noscript>

它在联系页面上运行良好,但如果我点击提交,则未验证我应该在联系页面中放置什么代码,以便它与验证一起使用。

【问题讨论】:

  • 所以你把你的代码放在那个页面,它没有显示?
  • 是的,它在仪表板->页面->联系页面上不起作用

标签: wordpress captcha


【解决方案1】:

您需要检查答案的有效性,而不仅仅是显示带有验证码质询的块。 https://web.archive.org/web/20121108134349/https://developers.google.com/recaptcha/docs/php

  <?php
 require_once('recaptchalib.php');
 $privatekey = "your_private_key";
 $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
   die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
     "(reCAPTCHA said: " . $resp->error . ")");
} else {
      // Your code here to handle a successful verification
}
?>

【讨论】:

    猜你喜欢
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多