0

I have made a simple guestbook where I have a <textarea> and a submit button. When the submit button is clicked multiple times in short period of time, the same data will go in to the database multiple times. How do I prevent this?

Here is the code:

def post(self):
    greeting = Greeting(parent=guestbook_key)


    greeting.content = self.request.get('content')
    greeting.put()
    self.redirect('/')

Here is the picture so you know what I am talking about: http://i.gyazo.com/87344b79b1eda82928385a44158d7d0b.png

dehrg
  • 1,721
  • 14
  • 17
Memmo Fiero
  • 109
  • 7

2 Answers2

0

The standard approach is to disable the Submit button immediately after it was clicked and before you make a call to the server. Then you reenable it - the timing depends on your app. You either reenable it right after the server call succeeded, or when a user returns to the same view (if you show a different view after the button is clicked).

Another approach is to disable the entire UI (for example, with a shaded glass panel shown on top of the entire screen) until the server responds.

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

Thank you very much! I really appreciate it. So i managed to block submit button with javascript.

Here is the code:

<form onsubmit="JavaScript:document.getElementById('submitbtn').disabled=true" >
<input type="submit" id="submitbtn">
</form>
Memmo Fiero
  • 109
  • 7