I have a contact form that I have added to my web page. After filling the form and clicking the "Submit" button, a "Successful" message appears. I did this with php request. However, when I refresh the page after this successful message, the request to send a message works again. How can I prevent this?
CodePudding user response:
You can use javascript window.history.replaceState
approach to prevent a resubmit on the page refresh.
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
You can also do a page redirection to same page or different page after form submission.
header('Location:'.$_SERVER['PHP_SELF']);