Skip to content Skip to sidebar Skip to footer

Prevent Double Submits

I am using GAE for an app that has various submit href buttons, and use javascript to submit. I am having a real tough time trying to figure out how to prevent multiple submits or

Solution 1:

Preventing it on the server side is not trivial - a second call may hit a different instance. So you need to deal with sessions. The code will get complex quickly.

I would recommend disabling the button before a call and reenabling it upon a response.

Solution 2:

You can use a javascript to disable all submit buttons on your page when a form is submitted. Maybe something like this:

document.forms[0].addEventListener('submit', function() {
    var btns = document.querySelectorAll('input[type="submit"]');
    for (var i = 0; i < btns.length; i++) {
        btns[i].disabled = 'disabled';
    }
});

If you need to also disable other elements you can modify the querySelector.

Post a Comment for "Prevent Double Submits"