Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent form from being submitted twice

I have a simple php form, like this:

<?php

if(isset($_POST['myform']))
   // email...
else
   // display form

the problem is that if I refresh the page after I submit the form, it gets submitted twice. How can I prevent this from happening?

like image 545
Alex Avatar asked Sep 01 '10 00:09

Alex


People also ask

How do you stop a form from being submitted twice?

A simple fix is to simply remove any "submit" handlers on the form before adding the new one.

How do I restrict a submission form?

The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML <form> element.

How do you stop form from resetting on submit?

You can use preventDefault method of the event object. Show activity on this post. Alternatively, you could use event.


1 Answers

You should perform a REDIRECT to a page with a message that the data was inserted... and a back button to go to the form again (if you want to)...

To redirect using PHP use the header function:

header('Location: http://www.example.com/');
like image 118
Garis M Suero Avatar answered Sep 17 '22 15:09

Garis M Suero