Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Preventing Double submit on refresh/back


Marked - 9:41 am on May 13, 2010 (gmt 0)


Hi all,

I'm trying to correct the issue of double submit in my script. I have done a bit of googling, but most solutions that i have found arn't quite what im looking for...

In my script, i have something like the following (on a single page):
if(isset($_POST['hidden_field']))
{
execute some code when the form is submitted
}

<form method="POST" action="">
<input type="hidden" value="hidden_field" name="hidden_field"/>
</form>

So basically the form and code when the form is submitted are in the same file. A quick example of what is happening is when you add or delete a certain item via the form, if you click back on the browser or refresh the page it tries to submit again. This is the double submit problem.

In my searches i mostly found scripts to disable buttons, but this didnt work. What i want to happen is when you submit the form, and the page reloads, it no longer tried to submit again when the page is refreshed or the back button is clicked. I heard the best way to do this is by redirect and changing POST to GET.

Does anyone know how i can go about getting this working?

Thanks in advance,
Mark.


Thread source:: http://www.webmasterworld.com/php/4131929.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com