简体   繁体   English

Google Recaptcha和2个或更多表单在一页中发布

[英]google recaptcha and 2 or more form in one page issue

I try work with new google recaptcha. 我尝试使用新的Google 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. 对于form1,它输出Recaptcha值。 so it works. 这样就可以了。

but for form 2 it is empty. 但对于表格2,则为空。

what is my wrong? 我怎么了

solved by this google guide. 通过此Google指南解决。

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

hope helps others for same problem. 希望可以帮助其他人解决同样的问题。

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

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