Karl Stulik
Karl Stulik

Reputation: 990

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 doubl-clicking. I have tried various methods to disable or remove the href with javascript.

But I am thinking if there is maybe a method to prevent this in the backend.

What methods would you recommend I use?

Upvotes: 0

Views: 115

Answers (2)

Gwyn Howell
Gwyn Howell

Reputation: 5424

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.

Upvotes: 0

Andrei Volgin
Andrei Volgin

Reputation: 41100

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.

Upvotes: 1

Related Questions