google recaptcha V2完成后自动发送表单

时间:2017-09-09 17:22:31

标签: javascript php jquery html recaptcha

我在我的网站上安装了google recaptcha V2,并且我想在google recaptcha完成时自动提交表单(没有按任何按钮),这是我的代码......

$secretKey='HIDDEN';
$responseKey=$_POST['g-recaptcha-response'];
$IP=$_SERVER['REMOTE_ADDR'];
$url="https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$IP";
$response=file_get_contents($url);
$response=json_decode($response);
    if($response->success){
         ....execute some php
    }

这是我的表格......

<form action="" method="post" class="Form" enctype="multipart/form-data">
      <div class="g-recaptcha"  data-sitekey="HIDDEN"></div>
</form>

感谢阅读,祝你有愉快的一天!

1 个答案:

答案 0 :(得分:0)

添加像这样的回调

<div class="g-recaptcha" data-sitekey="your-key-here" data-callback="submitForm" ></div>

然后在您的javascript代码中包含类似的内容

<script>
var submitForm = function () {
    $("#formID-goes-here").submit();
}
</script>