Disabling double submit prevent sending submit name [duplicate]

独自空忆成欢 提交于 2020-02-29 06:47:10

问题


I run into the bug with my multi form page:

I have two forms:

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

And this JavaScript to prevent double submit:

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

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
}

But JS is preventing this, why?

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

UPDATE:

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>

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.

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

Without this JS everything is working as expected.


回答1:


Use a class instead of an id on this : id="single-submit".

An id must be unique.



来源:https://stackoverflow.com/questions/38207721/disabling-double-submit-prevent-sending-submit-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!