2 Replies - 3588 Views - Last Post: 04 May 2010 - 03:50 AM

#1 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Stop form reposting on back and refresh

Posted 03 May 2010 - 02:48 PM

Hi, not 100% sure if this is the right forum for this question.

I have a form (well actually a webpage with multiple forms) which submit to various pure php scripts (depending on the form being submitted) that will either die, send the user to a error page, or redirect back to the page with all of the forms, with the updated data ready for editing again.

My problem is that I have a picture upload form on the page, and after uploading the picture and submitting the form, the php script is executed and the user is returned to the same page with the modified picture.
If the user clicks on the picture (show full size) and then clicks back on the browser the form is resubmitted, also if the page is refreshed the form is submitted again.

What is the best way to stop this from happening?

The form is simple, just uses method=post enctype=multipart/form-data.
If any more information is needed please just ask.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Stop form reposting on back and refresh

#2 jrm402  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 333
  • Joined: 18-March 10

Re: Stop form reposting on back and refresh

Posted 03 May 2010 - 03:01 PM

What I do is after a successful form submit, to clear the $_POST variable, I load the page again using header('Location: ' . $_SERVER['PHP_SELF'] . '?act=success');. That way it was like the user just got to the page and there is no form data stored anymore. You can then use if($_GET['act'] == 'success') to display confirmation messages.
Was This Post Helpful? 1
  • +
  • -

#3 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Re: Stop form reposting on back and refresh

Posted 04 May 2010 - 03:50 AM

View Postjrm402, on 03 May 2010 - 02:01 PM, said:

What I do is after a successful form submit, to clear the $_POST variable, I load the page again using header('Location: ' . $_SERVER['PHP_SELF'] . '?act=success');. That way it was like the user just got to the page and there is no form data stored anymore. You can then use if($_GET['act'] == 'success') to display confirmation messages.


Thanks, that will come in good use later on.
In the meantime I have decided to use javascript to reset the forms that need it on page load. Not the best method but it is in a private area so does the job nicely.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1