验证码破坏了我的表单?

发布于 2024-07-26 16:07:43 字数 2809 浏览 1 评论 0原文

我已经在我的表单中实现了验证码,但它似乎没有得到验证。 我在下面添加了代码,以查看我的布局中是否有任何明显的内容以及如何修改它。 该帖子的公钥和私钥已被删除。

谢谢。

<h1>Contact</h1>
<form action="index.php" method="post">
<input type="hidden" name="required_fields" value="name, email, message" />
<input type="hidden" name="email_fields" value="email" />
<input type="hidden" name="html_template" value="form.tpl.html" />
<input type="hidden" name="mail_template" value="mail.tpl.txt" />
<input type="hidden" name="thanks" value="/thanks.php" />
<!-- <input type="hidden" name="error_page" value="./docu/error.html" /> -->
<table border="0" cellpadding="3" cellspacing="0">
<tr>
  <td><p>Full Name <span>*</span></p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="name" value="" size="40" /></td>
</tr>
<tr valign="bottom">
  <td><p>Phone</p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="phone" value="" size="40" />
  </td>
</tr>
<tr valign="bottom">
  <td><p>Email <span>*</span></p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="email" value="" size="40" />
  </td>
</tr>
<tr valign="top">
  <td><p>Message <span>*</span></p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><textarea name="message" cols="30" rows="10"></textarea></td>
</tr>
<tr valign="top">
  <td>&nbsp;</td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><p>

<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "";
$privatekey = "";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
            echo "You got it!";
    } else {
            # set the error code so that we can display it
            $error = $resp->error;
    }
}
echo recaptcha_get_html($publickey, $error);
?>  
      <input type="submit" name="send" value="Send" />
      <br />
      <span>*</span> = required field.</p></td>
</tr>
</table>
</form>

I have implemented a captcha in my form, but it doesn't seem to be validating. I have included code below to see if there is anything obvious in my layout and how I can go about modifying it. Public and private keys have been deleted for the post.

Thanks.

<h1>Contact</h1>
<form action="index.php" method="post">
<input type="hidden" name="required_fields" value="name, email, message" />
<input type="hidden" name="email_fields" value="email" />
<input type="hidden" name="html_template" value="form.tpl.html" />
<input type="hidden" name="mail_template" value="mail.tpl.txt" />
<input type="hidden" name="thanks" value="/thanks.php" />
<!-- <input type="hidden" name="error_page" value="./docu/error.html" /> -->
<table border="0" cellpadding="3" cellspacing="0">
<tr>
  <td><p>Full Name <span>*</span></p></td>
  <td>   </td>
  <td><input type="text" name="name" value="" size="40" /></td>
</tr>
<tr valign="bottom">
  <td><p>Phone</p></td>
  <td>   </td>
  <td><input type="text" name="phone" value="" size="40" />
  </td>
</tr>
<tr valign="bottom">
  <td><p>Email <span>*</span></p></td>
  <td>   </td>
  <td><input type="text" name="email" value="" size="40" />
  </td>
</tr>
<tr valign="top">
  <td><p>Message <span>*</span></p></td>
  <td>   </td>
  <td><textarea name="message" cols="30" rows="10"></textarea></td>
</tr>
<tr valign="top">
  <td> </td>
  <td>   </td>
  <td><p>

<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "";
$privatekey = "";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
            echo "You got it!";
    } else {
            # set the error code so that we can display it
            $error = $resp->error;
    }
}
echo recaptcha_get_html($publickey, $error);
?>  
      <input type="submit" name="send" value="Send" />
      <br />
      <span>*</span> = required field.</p></td>
</tr>
</table>
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷︶言冷语的世界 2024-08-02 16:07:43

我不能说你的验证码有什么问题,因为我不知道这个验证码实现的具体细节。

由于您没有使用发布的数据填写字段,因此您的表单已重置。 也许你并不打算这样做。

首先确保您的表单在没有验证码的情况下按预期工作,以确保问题出在验证码中。

I cannot say what is wrong with your captcha, because I don't know the specifics of this captcha implementation.

Your form is reset because you do not fill the fields with posted data. Perhaps you do not intend to.

First make sure your form works as expected without the captcha, to make sure the problem is in the captcha.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文