繁体   English   中英

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

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

我尝试使用新的Google Recaptcha。

我在一页中有几种表格。 所以我想为每种形式定义一个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,它输出Recaptcha值。 这样就可以了。

但对于表格2,则为空。

我怎么了

通过此Google指南解决。

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

希望可以帮助其他人解决同样的问题。

暂无
暂无

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

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