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?
A simple fix is to simply remove any "submit" handlers on the form before adding the new one.
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.
You can use preventDefault method of the event object. Show activity on this post. Alternatively, you could use event.
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/');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With