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