简体   繁体   English

提交仅适用于第二次点击

[英]Submit only works on second click

I have a form with a verification through Google reCaptcha.我有一个通过 Google reCaptcha 进行验证的表格。 But now I have to click the submit button twice.但现在我必须点击两次提交按钮。 I can't find the reason.我找不到原因。

My form is build like this (Smarty):我的表单是这样构建的(Smarty):

<form method="post" id="form">
   <input type="hidden" name="action" value="misdaden">
     <table>
        {foreach from=$misdaden item=item}
           <tr>
                <td class="coll">{$item['id']}</td>
                <td class="coll">{$item['name']}</td>
                <td class="coll">{$item['minmoney']}</td>
                <td class="coll">{$item['maxmoney']}</td>
                <td class="coll">{$item['difficulty']}</td>
                <td class="coll">{$item['percentage']}%</td>
                <td class="coll"><input type="radio" style="width:20px;" name="value" value={$item['id']} /></td>
           </tr>
        {/foreach}
    </table>
    <input type="submit" value="Misdaad plegen!" name="submit" class="submit" />
    <!--input class="button good large" name="submit" type="submit" value="Pleeg misdaad!"-->
</form>

My script is (JQuery):我的脚本是(JQuery):

$('#form').submit(function(e) {
    e.preventDefault();
    grecaptcha.ready(function() {
    grecaptcha.execute('6LesiMAUAAAAAAJ8G94kKbXxJj62_U2ajn-dzJzF', {action:'misdaden'})
              .then(function(token) {
                    $('#form').prepend('<input type="hidden" name="token" value="'+ token +'">');
                    $('#form').unbind('submit').submit();
                });
    });
});

I'm probably missing something obvious, but what?我可能遗漏了一些明显的东西,但是什么?

In the jquery script, you are unbinding the submit event handler for form on execution of captcha which is not required.在 jquery 脚本中,您将取消绑定执行验证码时表单的提交事件处理程序,这不是必需的。 Just submit the form, see below只需提交表格,见下文

$(document).ready(function() {
    grecaptcha.ready(function() {
    grecaptcha.execute('6LesiMAUAAAAAAJ8G94kKbXxJj62_U2ajn-dzJzF', {action:'misdaden'})
              .then(function(token) {
                    $('#form').prepend('<input type="hidden" name="token" value="'+ token +'">');
                    $('#form').submit();
                });
    });
});

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

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