【发布时间】:2011-04-20 17:15:36
【问题描述】:
我有一个 php 脚本,它使用以下行来提交表单:
<form action = "javascript:void(null);" onsubmit = "load_ajax();" name = "myform">
现在,为了防止机器人滥用我想要实施 reCAPTCHA 的表单,如下所述:
http://www.darksideofthecarton.com/2008/12/15/validating-recaptcha-with-jquery-and-ajax/
reCAPTCHA 逻辑工作正常,显示验证成功/失败消息,但未提交表单。这是我用来实现 reCAPTCHA 的代码:
<form action = "javascript:void(null);" onsubmit = "return validateCaptcha()" name = "myform">
我用来调用 load_ajax() 函数的验证部分(表示表单提交成功):
function validateCaptcha()
{
challengeField = $("input#recaptcha_challenge_field").val();
responseField = $("input#recaptcha_response_field").val();
//alert(challengeField);
//alert(responseField);
//return false;
var html = $.ajax({
type: "POST",
url: "ajax.recaptcha.php",
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
async: false
}).responseText;
if(html == "success")
{
$("#captchaStatus").html("Success. Submitting form.");
return false;
// Uncomment the following line in your application
load_ajax();
return true;
}
else
{
$("#captchaStatus").html("Image verification failed, Pls. enter the image verification code correctly.");
Recaptcha.reload();
return false;
}
}
</script>
我不是 php/javascript 专家,所以需要帮助。
谢谢
【问题讨论】:
-
我仍然不敢相信人们不知道如何不显眼地实现 jQuery。
<form action="return false;" ...是我生命中的祸根。
标签: php javascript jquery recaptcha