How to prevent Double Form Submission?

How do I prevent a Form from being Re-Submitted and/or Double-Submitted?

The more I read on this topic, the more complex it sounds. :frowning:

I am trying to create a simple Comment form, however I don’t want users to be able to re-submit the Form by hitting F5 repeatedly or clicking Back-Forward-Back-Forward repeatedly.

There must be some solid strategies to implement on the Server to prevent this from happening?

Thanks,

Debbie

Hi there,

Unfortunately this is something that doesn’t really have a definitive answer. For a long time now different people have found ways to counteract this from happening, but you can’t really prevent people from clicking the refresh button or the back button. You can hide the buttons on a user’s browser, but that’s basically it.

You can, however, set up a threshold for users to submit comments. You can set up a column in your database and call it last_posted and program that if the user submits anything within that threshold, to display an error and not submit it to the database.

There are other ways like disabling the submit button and even prevent double Intel before it’s submitted. Good luck choosing your counteract and let me know I can help you further.

I don’t see using client-side approaches as a solution because if JS is off, they do nothing.

This question really ties into another of mine, which is “How can I separate the Form from the Processing?”

I’m new to PHP, but it doesn’t seem like it should be that hard to program things so if a person re-appears on a page that the page is not re-run.

How do real sites like Amazon.com do it?

Debbie

Sponsor our Newsletter | Privacy Policy | Terms of Service