验证码问题
我在网页中使用的表单有问题。
它允许验证码,但它也会发送电子邮件而不验证验证码框中的字段。 该表单使用 Ajax 和 PHP。
接下来我粘贴了代码:
<br> <br> <div id="fields">
<form action="javascript:alert('success!');">
<label>Nombre</label><INPUT class="textbox" type="text" name="name" value=""><br />
<label>eMail</label><INPUT class="textbox" type="text" name="email" value=""><br />
<label>Asunto</label><INPUT class="textbox" type="text" name="subject" value=""><br />
<label>Mensaje</label><TEXTAREA class="textbox" NAME="message" ROWS="5" COLS="25"></TEXTAREA><br />
<?php
require_once('recaptchalib.php');
// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LekPAQAAAAAAFoAJRfRtd9vmlzA9m-********";
$privatekey = "6LekPAQAAAAAAFqNcNsrnZba0-ZMg-********";
# 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 "Bien escrito!";
} else {
# set the error code so that we can display it
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br/>
<label> </label><INPUT class="button" type="submit" name="submit" value="Enviar">
</form>
</div>
</fieldset>
非常感谢。
大卫。
I have a problem with the form I'm using in my webpage.
It allows the recaptcha but It also sends the email without validating the fields in the recaptcha box. This form is using Ajax and PHP.
I've pasted the code next:
<br> <br> <div id="fields">
<form action="javascript:alert('success!');">
<label>Nombre</label><INPUT class="textbox" type="text" name="name" value=""><br />
<label>eMail</label><INPUT class="textbox" type="text" name="email" value=""><br />
<label>Asunto</label><INPUT class="textbox" type="text" name="subject" value=""><br />
<label>Mensaje</label><TEXTAREA class="textbox" NAME="message" ROWS="5" COLS="25"></TEXTAREA><br />
<?php
require_once('recaptchalib.php');
// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LekPAQAAAAAAFoAJRfRtd9vmlzA9m-********";
$privatekey = "6LekPAQAAAAAAFqNcNsrnZba0-ZMg-********";
# 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 "Bien escrito!";
} else {
# set the error code so that we can display it
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br/>
<label> </label><INPUT class="button" type="submit" name="submit" value="Enviar">
</form>
</div>
</fieldset>
Thanks a lot.
David.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您需要在再次显示表单之前检查 reCAPTCHA。 PHP 代码将位于表单的第一行上方,最好是在生成任何 HTML 之前,以便将用户重定向到感谢页面。
The problem is that you need to check the reCAPTCHA before you display the form again. The PHP code would go above the first line of the form, perferrably before any HTML is generated so the user can be redirected to a thank you page.