如何在表单提交中验证Google reCaptcha [英] How to Validate Google reCaptcha on Form Submit
问题描述
最近,Google彻底改革了他们的reCaptcha API并将其简化为一个复选框。 $ b
问题是,我可以提交包含reCaptcha的表单而不检查它,表单将忽略reCaptcha。
在您使用私钥等将表单发送到PHP文件之前,我在开发人员指南中没有看到任何提及。我不知道如何验证表单,以确保新的reCaptcha是由用户填写的。
我是否错过了一些东西?这个PHP文件仍然需要私钥吗?
到目前为止,我对reCaptcha的所有信息是:
< div data-type =imageclass =g-recaptchadata-sitekey =My Public Key>< / div>
如果您想检查用户是否点击我不是机器人
复选框,您可以使用reCaptcha API提供的 .getResponse()
函数。
如果用户没有验证自己,它将返回一个空字符串,如下所示:
if(grecaptcha.getResponse()==){
alert(You can not proceed!);
} else {
alert(Thank you);
}
在用户验证自己的情况下,响应将是一个非常长的字符串。
有关API的更多信息,请参阅此页面: reCaptcha Javascript API
Recently, Google completely overhauled their reCaptcha API and simplified it to a single checkbox.
The problem is, I can submit a form with the reCaptcha included without checking it and the form will ignore the reCaptcha.
Before you had to send the form to a PHP file with the private key et al, but I'm not seeing any mention of that in their Developer's Guide. I have no idea how to validate the form to be sure the new reCaptcha was filled by the user.
Am I missing something? Is that PHP file with the private key still required?
All I have for the reCaptcha so far is:
<div data-type="image" class="g-recaptcha" data-sitekey="My Public Key"></div>
If you want to check if the User clicked on the I'm not a robot
checkbox, you can use the .getResponse()
function provided by the reCaptcha API.
It will return an empty string in case the User did not validate himself, something like this:
if (grecaptcha.getResponse() == ""){
alert("You can't proceed!");
} else {
alert("Thank you");
}
In case the User has validated himself, the response will be a very long string.
More about the API can be found on this page: reCaptcha Javascript API
这篇关于如何在表单提交中验证Google reCaptcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!