Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mallaury's avatar

How to prevent form to be submitted twice

Hello,

I know this question has been asked before, but the solutions don't work for me.

The first solution I tried was this:

$('form').submit(function() {
    $(this).unbind('submit');
    $(this).submit(function() {
        return false;
    });
});

The problem with this solution is that if a JS alert is displayed to indicate that the nickname is not correct, the button will be disabled and therefore we won't be able to submit the form again.

The second solution tested:

$('form').submit(function(){
            $(':submit').html('submitting...').addClass('disabled');
 });

This solution is not clean, because the button is not reactivated if the user navigate back (from the browser).

Do you have other solutions? Or maybe a way to use the first solution, but blocking the sending only for 1 second (I tried it, I didn't find how to do it).

Thank you very much.

0 likes
1 reply
a-hussien's avatar

To prevent the form from being submitted twice disable the form submission button while request processing.

Please or to participate in this conversation.