How To Stop Form Re-submission On Page Refresh.

Md Riyazuddin Verified
Basically, the general idea is to redirect the user to some other pages after the form submission which would stop the form re-submission on page refr
<script>
if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}
</script>

or 

if(!empty($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST'){
 $data = // processing codes here
 unset $data;
}

you can choose any one which you want it and compatible for your plugin and theme.


                                                        
if(!empty($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST'){
 $data = // processing codes here
 unset $data;
}
<script>
if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}
</script>

This method is quite easy and blocks the pop up asking for form re-submission on refresh once the form is submitted

References and Credits

Comments

we

webnewcon 2023-10-13 07:45:24

good

Leave a Reply Cancel reply


Leave a Comment