dongxuan2577 2014-12-12 19:15
浏览 534

如何在表单提交上验证Google reCaptcha

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>
  • 写回答

11条回答 默认 最新

  • douzhang2092 2014-12-15 09:03

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化