简体   繁体   English

ReCaptcha 2.0:如果 recaptcha 成功,则在回调时启用提交按钮

[英]ReCaptcha 2.0: enable Submit button on callback if recaptcha successful

I have a very simple form as follows.我有一个非常简单的表格如下。 I want to make it so that the Submit button is disabled, and only enabled after the user has successfully completed the ReCaptcha.我想让提交按钮被禁用,并且只有用户成功完成 ReCaptcha 后才启用。

I'm assuming I'm going to need some Javascript / jQuery to do this.我假设我需要一些 Javascript / jQuery 来做到这一点。

Google's documentation on ReCaptcha 2.0 seems really sparse and dense (to me, anyway).谷歌关于 ReCaptcha 2.0 的文档似乎非常稀疏和密集(无论如何对我来说)。 I'd appreciate some pointers:我很感激一些指示:

<form action="something.php" method="post">
    Name: <input type="text" size="40" name="name"><br><br>
    <div class="g-recaptcha" data-sitekey="############-#####"></div>
    <input type="submit" value="Submit" >
</form>

i did the same thing on my test site.我在我的测试站点上做了同样的事情。 however, i used a button instead of submit, so here:但是,我使用了按钮而不是提交,所以在这里:

you must add the property data-callback="enableBtn" data-callback property executes the function specified after accomplishment of recaptcha.您必须添加属性data-callback="enableBtn" data-callback 属性执行 recaptcha 后指定的功能。

<div class="g-recaptcha" data-sitekey="############-#####" data-callback="enableBtn"></div>

and set the id of the button to whatever id you want to and set it to disabled:并将按钮的 id 设置为您想要的任何 id 并将其设置为禁用:

<input type="button" value="Submit" id="button1" disabled="disabled">

then on javascript make a function to enable the button然后在 javascript 上创建一个函数来启用按钮

 function enableBtn(){
   document.getElementById("button1").disabled = false;
 }

hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM