pythongoogle-app-enginetextareagqlgqlquery

How to prevent multiple submission in database


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


Solution

  • 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.