【问题标题】:Contact form example not working with reCAPTCHA联系表格示例不适用于 reCAPTCHA
【发布时间】:2015-05-26 01:39:24
【问题描述】:

有人可以帮我处理这个电子邮件联系表吗? 我完全不知道我在做什么,而且我以前从未做过类似的事情。

我正在处理这个例子https://css-tricks.com/examples/NiceSimpleContactForm2/

我已将示例放在http://www.techagesite.com/contact/index.php

我不确定我必须做什么才能让 reCAPTCHA 正常工作。事实上,它甚至没有出现在作者在线版本上。

我不知道我是否应该发布所有包含的 php 文件的代码,或者你是否可以从示例 zip 本身中解决它。

【问题讨论】:

  • 如果有更简单的解决方案,那么我很乐意尝试一下。

标签: css recaptcha contact-form


【解决方案1】:

Check out this page, which is where this is shamelessly taken from:

从您的代码示例中,您似乎正在尝试在<iframe> 中生成recaptcaha。这不会很容易 - 验证码的目的是让您提交一个带有附加值的表单,您的代码应该验证服务器端。

只需起草一个普通的 HTML 表单(去掉 iframe 部分),然后删除创建 recaptacha 部分的 php 代码,就像在表单 (contact_form.php) 中一样:

  <form method="post" action="verify.php">
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

当页面被渲染时,php 被替换为 javascript。当用户提交您的表单时,它会被发布到上面action 中的 url,这是验证 capatcha 输入 (verify.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
  }
  ?>

就是这样。

【讨论】:

    猜你喜欢
    • 2018-02-24
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 2022-10-06
    • 2020-08-17
    • 2015-10-03
    相关资源
    最近更新 更多