0

I am trying to prevent a form's save button from being clicked twice. When I set onsubmit='save.disabled=true' in the form's tag, the button is disabled when submitted but the POST data no longer contains the "Save" key and value. Since I have multiple buttons on the form, I need to know which one was clicked. Is there another way to disable the save button without this side effect?

<form method='post' action='dosomething.php?' enctype='multipart/form-data' onsubmit='save.disabled=true'>
    ... input types & Other buttons ...
    <input type='submit' name='save' value='Save'>
</form>
mseifert
  • 5,390
  • 9
  • 38
  • 100
  • have a look at http://stackoverflow.com/a/2155126/87956 – Vinay Pandey Oct 09 '13 at 05:26
  • It seems this answer is asp specific. But it did give me the idea that, instead of changing the button's value, would it work to change the button's 'name' property each time it is clicked, so that I can recognize whether it is Save, Save1, Save11... – mseifert Oct 09 '13 at 05:33
  • Why just don't hide the button instead disabling it? – bksi Oct 09 '13 at 05:39
  • Yes that works. If there is no better way to do it. As I don't like disappearing buttons, I probably will create a new disabled fake button to display in its place. If there is no better solution, create a post for this and I will accept it. – mseifert Oct 09 '13 at 05:44

2 Answers2

0

Can you assign another variable the value of the button you clicked before disabling? Something along the lines of:

$('#submit').click(function () {
    $('#form').append("<input type='hidden' name='" + $(this).attr('name') + "' value='"+
                     $(this).attr('value')+ "' />");
    $(this).attr("disabled", true);
    $('#form').submit();
    });
Neil Neyman
  • 2,116
  • 16
  • 21
0

Why just don't hide the button. When you disable form element, it doesn't appear in $_POST.

<form method='post' action='dosomething.php?' enctype='multipart/form-data' onsubmit='save.style["visibility"] = "hidden"'>
        ... input types & Other buttons ...
        <input type='submit' name='save' value='Save'>
    </form>
bksi
  • 1,606
  • 1
  • 23
  • 45