Preventing [F5] submission

Form handling may require the script to identify if the user has first submitted the form or if he has pressed the key [F5] to submit the form again. Indeed, if form submission triggers an insert into database query, you may want the insertion not to happen twice.

Basically, the only thing to do is to post a hidden field (called “process” in my example) containing the Unix timestamp of the time when the form was generated (microtime(true) in PHP). Then write a short PHP function that will

  • compare the posted process value with a Session variable called “process”. If the posted process variable equals the Session value, trigger the error : “Please use submit button”
  • if it doesn’t, process form, then store the posted process time in a Session variable ($_SESSION["process"]).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>