CodeIgniter Forums
submitting a form for preview in one step + unsetting post data to prevent second submitting with reloading - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: submitting a form for preview in one step + unsetting post data to prevent second submitting with reloading (/showthread.php?tid=4996)



submitting a form for preview in one step + unsetting post data to prevent second submitting with reloading - El Forum - 12-30-2007

[eluser]Isos[/eluser]
Hello community.

Let me explain more on this!

When I submit a form to preview in another page, I have a problem that post data are kept in the server request so if some user would accidentally press F5 the data will be submitted again. Any tip on how to unset (not only to empty variables) the post data set with form validation?

Now I know that some would suggest submitting to a temp page that says "your have successfully submitted data" and redirect to preview .. I want to do all that in one step. I think it's possible.

I used one way before which is a sql query that checks if the exact same data where submitted then don't perform insert into table syntax again. I feel that's not so much secure and effective though.

Thanks in advance.

Isos


submitting a form for preview in one step + unsetting post data to prevent second submitting with reloading - El Forum - 12-30-2007

[eluser]adamp1[/eluser]
I don't think you can unset POST variables from the users HTTP request. You can unset them on your script but the user will still be able to submit them again.

The best method I can think of is to put a hidden field in the form which has a unique identifier in it (one which the user cannot guess the next increment but that also can be decoded). Then on your update page decode it and check if that ID is in the table. (That's if the user is adding a new field, if there are updating then it really doesn't matter does it if they resubmit the same data?)


submitting a form for preview in one step + unsetting post data to prevent second submitting with reloading - El Forum - 01-10-2008

[eluser]adamp1[/eluser]
I just thought of another way this could be done. You could store a session variable of the progress of the form submission. Then when they view the preview you set a flag saying they they have already submitted the data. Before adding the data to the data to the database you check if the flag exists, if it doesn't don't add the data.

I don't know if the session variable would be restored to its previous state on a refresh or not, without having a try.