Is there a way to keep a form resubmitting upon refresh or back-history that DOESN’T involve: .js, $_SESSION, or header('location:…)?
I am trying to display, process, and respond to a form all in the same script/document. So far everything works splendidly. I have created a class that I can instance for the form.
- Checks to see if it is submitted ( via a isset(_whateverMETHOD[‘someName’) )
- If the form has not been submitted, it simply displays the form
- If a query string (and it’s not submitted) is present, it reads a DB and FILLS the form, for editing.
- if it’s submitted, it runs a validation function.
4a) If validation fails, it clears the bad field, fills the form with the remaining data and displays the from along with error messages
4b) If validation passes it submits the data to the DB; and displays a ‘success’ ( instead of the form)
The problem is that refreshing the page resubmits the form ( creating duplicate entries in the DB).
I don’t want to include .js in this project, and $_SESSION or hidden fields seem a bit convoluted.
I was thinking that i could easily redirect the page to itself on successful submission, which would solve the refresh issue, but I am concerned that if I do that I wouldn’t be able to display the success message (as the from wouldn’t be able to tell whether this was a new request or redirect, on step 1)
I was hoping there was a way to unset( _whateverMETHOD['someName) in the form request to prevent resubmission or some way to pass a variable forward (other than GET, POST, or SESSION as the form class already employs these) toilet the scrip know the form was submitted and the success message should be displayed ?
I hope I am expressing this clearly. As always all suggestions are greatly appreciated.