0

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?

Karl Stulik
  • 961
  • 1
  • 12
  • 24

2 Answers2

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.

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
0

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.

Gwyn Howell
  • 5,365
  • 2
  • 31
  • 48