0

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.

ProgZi
  • 1,028
  • 3
  • 14
  • 25
  • `$("form").one('submit'`, try using `on(` instead of `one(`. – Tushar Jul 05 '16 at 15:52
  • typo ?? $("form").one – Deep Jul 05 '16 at 15:52
  • 2
    You have duplicate `id`, which is illegal html. fix your html, and things will probably start working better. – Marc B Jul 05 '16 at 15:53
  • Not a typo... `.one` triggers only one time. Google it! – Louys Patrice Bessette Jul 05 '16 at 15:54
  • Removed ids, added classes instead, tried `on(` instead, no luck. But now first AND second form does not return submit `name` – ProgZi Jul 05 '16 at 16:04
  • 1
    Please update your question to reflect all of the details. Comments are not a suitable place to include details or current status of the question. Since your question is currently closed, the *only* way to get it re-opened (and available for new answers) is to sufficiently describe the question in a way that clearly indicates that it's not a duplicate. – Michael Gaskill Jul 05 '16 at 16:44
  • See also: https://stackoverflow.com/q/60171869/334451 – Mikko Rantalainen Feb 12 '20 at 08:52

1 Answers1

2

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

An id must be unique.

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
  • Changed, but problem stayed the same, except now I don't receive submit `name` from neither of two forms. – ProgZi Jul 05 '16 at 20:15
  • Hew... Where do you want it to be "received". Did you set `action` and `method` ? It would look like this : `
    `.
    – Louys Patrice Bessette Jul 05 '16 at 20:22
  • Yes, just didn't want to put everything, so it be more clear. As I mentioned, everything is working as expected without this JS chunk that is preventing double click, to be more sure I removed other JS, during the tests. – ProgZi Jul 05 '16 at 20:59
  • You SHOULD edit your question... As the `id` problem isn't the only problem. Your question is now marked as a [duplicate] because of that. If you edit it... Including all relevant code, it will be re-opened. Hit the "edit" link below your question. – Louys Patrice Bessette Jul 06 '16 at 02:16