google recaptcha和两页或多页表格一页

时间:2023-01-17 13:30:14

I try work with new google recaptcha.

我尝试使用新的谷歌recaptcha。

I have several form in one page. So I want define for per form, one recpatcha.

我在一个页面中有几个表单。所以我想为每个表单定义一个recpatcha。

Also I want send form via jQuery...

我也希望通过jQuery发送表单...

So I do this:

所以我这样做:

first:

<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>

And here is sample forms code:

以下是示例表单代码:

<form id="form1">  //form 1
<div id="RecaptchaField1"></div>
</form>

<form id="form2">  //form 2
<div id="RecaptchaField2"></div>
</form>

And finaly jquery code:

最后的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){...

Now in target page of jquery, If I print $_post:

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

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

for form1, It prints recaptcha value. so it works.

对于form1,它打印recaptcha值。所以它有效。

but for form 2 it is empty.

但对于表格2,它是空的。

what is my wrong?

我错了什么?

1 个解决方案

#1


0  

solved by this google guide.

通过这个谷歌指南解决。

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

hope helps others for same problem.

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

#1


0  

solved by this google guide.

通过这个谷歌指南解决。

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

hope helps others for same problem.

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