Form is resubmitted when the back button is pressed

Devansh Kumar picture Devansh Kumar · Jul 7, 2012 · Viewed 11.7k times · Source

I have a problem with my contact form that I have made using HTML and PHP. When the user clicks submit it redirects to another page where the user gets the message, "Your message has been sent". It then automatically redirects to the home page. But when the user clicks the back button, the message appears again and the form is resubmitted. Consequently I get two identical messages sent to my email!

How can I fix this?

Answer

brezanac picture brezanac · Jul 7, 2012

Take a look at Preventing form resubmission and Prevent Back button from showing POST confirmation alert where you will find useful info how to make redirects which won't trigger form re-submission when the Back button is clicked.