Add to collection
Md Riyazuddin

Md Riyazuddin

Verified

How To Stop Form Re-submission On Page Refresh.

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

Try Yourself in Code Editor    

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

<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>

References and Credits

Tagged with: wordpress

Comments 0

  • Sorry!! No comment posted yet. Become the first user to give comment.
Add a comment

Would you like to write for w3 sniff?

Become part of an amazing group of contributors and authors and start writing for us

Join Now
<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>
Feedback submitted successfully.