Stop page resubmit after message with F5

After submitting the form with post method f5 will be re-submitted. The best way to avoid this is by not redirecting the page. Don't like to bother the user this way. Stackoverflow is immune to f5, but I can't see the redirects after asking the question.

+2


source to share


3 answers


StackOverflow is pretty heavy on AJAX, so you see the behavior you see.

If you don't want to receive all the AJAXy you need redirects. Redirects of this kind should be transparent to the user:



if (! empty($_POST)){
   // Do something with the contents of $_POST
   header('Location: success.php');
}

      

Now, if your validation fails, you will probably reload the form with some error messages, and the F5 interception will re-submit the data. But if the operation is successful, the user will be redirected to the success page and they can hammer f5 all day without re-setting the data and potentially create repetitive actions.

+6


source


Get after message

  • Form makes a POST request
  • Code processes form
  • Forwarding code using location header


Result: The updated resulting page will just render it again since it was done using GET.

+7


source


The standard approach for achieving this effect is to use an HTTP redirect, which is not obvious to the user (so I assume you are referring to a meta-refresh delay redirect).

See Post a redirect Get a template .

+3


source







All Articles