禁用双重提交将阻止发送提交名称 [英] Disabling double submit prevent sending submit name

查看:81
本文介绍了禁用双重提交将阻止发送提交名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在多表单页面上遇到了该错误:

I run into the bug with my multi form page:

我有两种形式:

<form>
<input type="submit" id="single-submit" name="form_1" value="Submit 1"/>
</form>

<form>
<input type="submit" id="single-submit" name="form_2" value="Submit 2"/>
</form>

此JavaScript可以防止重复提交:

And this JavaScript to prevent double submit:

$("form").one('submit', function() {
    $('#single-submit').prop("disabled", true);
});

我正在尝试使用php获取提交名称:

I'm trying to get the submit name in php:

if(isset($_POST['form_1']))
{
    // form 1 submitted
}

if(isset($_POST['form_2']))
{
    // form 2 submitted
}

但是JS阻止了这个,为什么呢?

But JS is preventing this, why?

我可以从第二,第三...表格中收到name="".但不是页面上的第一个表格.

I can recieve submit name="" from second, third... form. But not from the first form on page.

更新:

删除了双重ID,而是添加了类:

Removed double ids, added classes instead:

<form action="example.com/process" method="post" accept-charset="utf-8">
<input type="submit" class="single-submit" name="form_1" value="Submit 1"/>
</form>

<form action="example.com/process" method="post" accept-charset="utf-8">
<input type="submit" class="single-submit" name="form_2" value="Submit 2"/>
</form>

此JavaScript可以防止重复提交:

And this JavaScript to prevent double submit:

$("form").one('submit', function() {
    $('.single-submit').prop("disabled", true);
});

此外,第一个和第二个表单现在不返回提交名称.

Moreover now first AND second form does not return submit name.

还尝试了on(,没有运气.
因此,JS似乎还是有问题.

Also tried on( instead, no luck.
So it seems something still wrong with JS.

没有此JS,一切都会按预期运行.

Without this JS everything is working as expected.

推荐答案

在此id="single-submit"上使用class而不是id.

id必须是唯一的.

这篇关于禁用双重提交将阻止发送提交名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆