php - reCaptcha 值未出现在 $_POST 中

标签 php forms dom handler recaptcha

我正在尝试在我的网站上使用 reCaptcha,recaptcha_challenge_field 和 recaptcha_response_field 没有被添加到后端的 $_POST 数组中 - 但我表单中的其余变量是。

有什么想法吗?我已经仔细检查了公钥/私钥。

这是生成的 HTML:

 <form action='myform.php' name='myform' id='myform' method='post' enctype='multipart/form-data'>
    <tr class='select'>
      <td class='label'>Name:</td>

      <td>
        <input type='text'  name='name'  id='name'  class='inputtext'  maxlength='25'  size='25' >
      </td>
    </tr>
    <tr class='select'>
      <td class='label'>Email:</td>
      <td>
        <input type='text'  name='email'  id='email'  class='inputtext'  maxlength='25'  size='25' >

      </td>
    </tr>
    <tr class='select'>
      <td class='label'>Message:</td>
      <td>
        <textarea class='inputtext' name='message'  rows='10' cols='45'></textarea>
      </td>
    </tr>

    <tr class='select'>
      <td class='label'>Are you human?</td>
      <td>
        <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=MY_KEY"></script>

    <noscript>
        <iframe src="http://api.recaptcha.net/noscript?k=MY_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>
      </td>
    </tr>

    <tr>
      <td>
      &nbsp;
      </td>
      <td style='text-align: left;' colspan='2'>
        <input type='submit' class='button' value='Send message'>
      </td>
    </tr>
  </form>

到目前为止,这是我的处理程序:

print_r($_POST);


require_once('inc/recaptchalib.php');
$privatekey = "MY_PRIVATE_KEY";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

print_r($resp);

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

任何帮助将不胜感激。 谢谢,

最佳答案

可以想象,由于交错的方式,您可能会遇到 DOM 问题 <table><form> .尝试移动您的 <form></form> <table> 之外的标签和 </table>分别。

关于php - reCaptcha 值未出现在 $_POST 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/902627/

相关文章:

php - 嵌入式YouTube链接图片未出现在Facebook中

javascript - 如何将 id 或 class 添加到 Drupal 中的表单元素?

javascript - Vue.js:如何在选择下拉框中获取选项的属性?

php - 如何获取远程服务器的时间?

php - 如何在 Laravel 中制作带有产品属性的智能过滤器

php - Javascript:通过post发送数组

javascript - 检测特定文本框是否具有焦点

ruby-on-rails - Rails 3表单助手: UTF8 and other hidden fields

dom - xPath loadHTML在 “unexpected end tag”的Table元素上被触发

html - 在 DOM 中存储 JSON 的最佳实践