How to avoid $_POST resending data? |
[eluser]webbymonk[/eluser]
After being web programmer for sometime found some problem on inserting data to database especially using $_POST...if we accidentally pressing F5 data will be resend... I found a tutorial here http://www.ajaxray.com/blog/2008/01/12/h...d-warning/ But I am not sure it is the only way by storing $_POST data into session... Any other solutions?
[eluser]LuckyFella73[/eluser]
In case you want to show the user some details he just submitted in a form, using sessions (native or CI-session) would be nessesary or recommended. You could add the db insert-id info as an url segment and start a query at the redirect-page but that would open your database as you could just edit the url segment containing the id and get infos about all your other db entries! You also could build the redirect url depending on the submitted data but that could become "fiddly" (don't know if you can use this word - I just googled to find a similar world I would use in my language). If it's just a small set of data it would be ok this way. But I would prefer using sessions.
[eluser]webbymonk[/eluser]
I have implement session already in the situation... Here is my steps 1. The Post data I copied it into session 2. Displaying the session data into a redirected page 3. Insert session data into DB 4. Unset/Clear the session... btw I google for fiddly -> requiring close attention to detail : fussy ; especially : requiring an annoying amount of close attention )
[eluser]Michael Wales[/eluser]
Eliminating refresh reposting is very easy in CodeIgniter: Code: if ($this->validation->run()) { Since you are redirecting after the submission of data, it's impossible for the refresh to resubmit.
[eluser]webbymonk[/eluser]
Similiar to what i did... but my case is for temporary data,,, After the user confirm, the data will be sent to database,,,so I will have to use session... I think redirecting is good especially for upload file case. But I don't know how to write the upload data into session because i have multiple upload field $this->upload->data() is multi dimension array... Here is my code i wrote in the helper Code: <?php and this is my controller Code: $this->load->helper(array('file','photo_upload_helper')); |
Welcome Guest, Not a member yet? Register Sign In |