dongxuan2577 2014-12-12 19:15
浏览 534
已采纳

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

Recently, Google completely overhauled their reCaptcha API and simplified it to a single checkbox.

reCaptcha

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退