谷歌重述和2个或更多的形式在一页的问题

google recaptcha and 2 or more form in one page issue

本文关键字:问题 一页 2个 谷歌      更新时间:2023-09-26

我尝试使用新的谷歌重述。

我在一页纸上有好几张表格。所以我想为每个表单定义一个recpatcha。

我还想通过jQuery发送表格。。。

所以我这样做:

第一个:

<script src="//www.google.com/recaptcha/api.js?hl=fa&onload=CaptchaCallback&render=explicit" async defer></script>
    <script type="text/javascript">
    var CaptchaCallback = function(){
        grecaptcha.render('RecaptchaField1', {'sitekey' : '<?php echo SITERECAPTCHAT;?>'});
        grecaptcha.render('RecaptchaField2', {'sitekey' : '<?php echo SITERECAPTCHAT;?>'});
    };
    </script>

这是示例表单代码:

<form id="form1">  //form 1
<div id="RecaptchaField1"></div>
</form>
<form id="form2">  //form 2
<div id="RecaptchaField2"></div>
</form>

最后jquery代码:

$.post('index.php?id=form1', {
        recaptcha: $('#g-recaptcha-response').val(),
        async: true
       }).done(function(data){...

$.post('index.php?id=form2', {
        recaptcha: $('#g-recaptcha-response').val(),
        async: true
       }).done(function(data){...

现在在jquery的目标页面中,如果我打印$_post:

foreach ($_POST as $key => $value)

对于form1,它打印重述值。所以它是有效的。

但对于中二,它是空的。

我怎么了?

通过本谷歌指南解决。

https://developers.google.com/recaptcha/docs/display

希望能帮助别人解决同样的问题。