Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel提交按钮_Php_Laravel - Fatal编程技术网

Php Laravel提交按钮

Php Laravel提交按钮,php,laravel,Php,Laravel,我有两个订阅表单,一个在主页,另一个在页脚。它们都有相同的回调函数,但页脚中的回调函数不会触发脚本 <footer id="main-footer"> ... <form method="post" action="/subscribe" id="subscribe-form-footer"> ... <button type="button" class="btn btn-default g-recaptcha" d

我有两个订阅表单,一个在主页,另一个在页脚。它们都有相同的回调函数,但页脚中的回调函数不会触发脚本

<footer id="main-footer">
    ...
    <form method="post" action="/subscribe" id="subscribe-form-footer">
        ...
        <button type="button" class="btn btn-default g-recaptcha" data-sitekey="-------" data-callback='onSubmitFooter'>{{trans('content.input_submit')}}</button>

    </form>
</footer>

...
...
{{trans('content.input_submit')}
我尝试将脚本放在文档的头部、页脚标记的内部、页脚标记的末尾,但它没有触发它。以下是脚本:

<script>
    function onSubmitFooter(token) {
        document.getElementById("subscribe-form-footer").submit();
    }
</script>

函数onSubmitFooter(令牌){
document.getElementById(“订阅表单页脚”).submit();
}
编辑:


尽管由于我更正了ID,但无论我将脚本放在何处,问题仍然存在。

使用下面的一个。在您的情况下,id不正确

<footer id="main-footer">
    ...
    <form method="post" action="/subscribe" id="subscribe-form-footer">
        ...
        <button type="button" class="btn btn-default g-recaptcha" data-sitekey="-------" data-callback='onSubmitFooter'>{{trans('content.input_submit')}}</button>

    </form>
</footer>
  <script>
        function onSubmitFooter(token) {
            document.getElementById("subscribe-form-footer").submit();
        }
    </script>

函数onSubmitFooter(令牌){
document.getElementById(“订阅表单页脚”).submit();
}

因此,第一个问题在@prasad的回答中得到了解决

您现在遇到的第二个问题是: 脚本以正确的方式调用,但仍无法运行。首先,我可以看到您正在使用
google-recapthca
。既然你告诉我们你在一个页面上使用了两个表单,这就是问题所在

Google-recapthca
通常不支持同一页面上的两个按钮

data-sitekey="-------"
发生这种情况时,如果不进行一些调整,其中一个脚本将无法正常工作

请参见下面的示例:


var-tcha1;
var-tcha2;
var myCallBack=函数(){
//在ID为“recaptcha1”的元素上呈现recaptcha1
recaptcha1=grecaptcha.render('recaptcha1'{
'sitekey':'6Lc_0f4saaaaf9za',//用您的站点密钥替换它
“主题”:“光”
});
//在ID为“recaptcha2”的元素上呈现recaptcha2
recaptcha2=grecaptcha.render('recaptcha2'{
'sitekey':'6Lc_0f4saaaaf9za',//用您的站点密钥替换它
“主题”:“黑暗”
});
};

请登录
电子邮件地址
密码
登录
报名表
电子邮件地址
密码
登录

将脚本更改为
document.getElementById(“订阅表单页脚”).submit()sitekey
,但不同的
id
变量。你试过了吗?我没有,因为你的解决方案使用的是经典的reCaptcha,我的解决方案使用的是不可见的reCaptcha,我不希望它被渲染,我希望它连接到一个按钮上。但即使没有这个,如果我删除第一个按钮,第二个按钮也不会触发该功能。就像在
标记下忽略脚本一样……好吧。那么问题应该介于这两种形式之间。页脚表单应该不同于普通表单,因为一个可以工作,另一个不能。你应该很好地比较这两种形式。查看诸如
标记属性和
属性之类的内容。
应该是JS问题还是什么问题,因为当我将它转换为带有submit类型的经典按钮时,它会正常提交