1

So, I've a website that, once you're logged-in, uses a form to let you post a thing. (I'm using PHP/MySQL under the hood, but it's not that important here).

The trouble is that when they post the thing, sometimes they double-click the "post a thing" button. That posts two things.

Sometimes the form takes a short about of time to process, so they click the "post a thing" button again. That posts three things.

What's the best way to stop multiple form entries?

I've thought about...

  1. Hiding the button with JavaScript as soon as they click it, so that they can't double-click it, but that's not been very successful
  2. Checking that the title of the thing that they've just posted isn't the same as the title of a thing already in the database - but that'll give them an error even though the thing has successfully been posted and I don't want that
  3. Checking that they're not posting more than one thing in the last 60 seconds, but again, that'll give them an error even though it's been successfully posted
  4. Instead of giving them an error in #2 or #3, take them somehow to the successful initial page thing

Am I overlooking a really simple method of avoiding a form being submitted twice? Is there something in HTML these days to stop this from happening?

3
  • 1
    This might be better asked on SO, but perhaps the most effective way to prevent this would be server side. Generate a unique identifier for the form prior to it being submitted, and then reject any subsequent submissions of the form with that ID. Feb 11 at 4:44
  • Why not use jquery and have a modal window pop onClick. It could have a message "your form is being processed" or whatever.
    – Steve
    Feb 11 at 6:53
  • Taking them to the successful initial page doesn't seem hard to me. You already know which thing it is because you identified it as duplicate. Have you implemented a redirect for it? Feb 11 at 10:11

1 Answer 1

2

Elsewhere, I'm told that a simple method to achieve this is simple JavaScript to, on-click, mark the button as disabled. That appears to potentially do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.