![]() |
Preventing double post data being resent - 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: Preventing double post data being resent (/showthread.php?tid=3238) |
Preventing double post data being resent - El Forum - 09-19-2007 [eluser]worchyld[/eluser] Typically when pressing submit on a form, and its sending POST data to itself, and you press F5, it'll bring up the message; Quote:The page you are trying to view contains POSTDATA. If you resend the data, any action the form carried out (such as a search, or an online purchase) will be repeated. In the past, I resolved this problem by doing this; Quote:1. Make the form page go to a processing file (process-something.php) How do you prevent the POSTDATA message/double posting on CI? I thought you could do it by replicating the same procedure (ie: having a processing file act as a middleman) but the POSTDATA message still appears, also I have to repeat a lot of code over, otherwise it'll complain it's missing a page variable. ie; Code: // This first controller just displays the form, it doesn't handle any processing. Code: // This is the view page. Its just a form, nothing more, nothing less. Code: // The processing middleman file Preventing double post data being resent - El Forum - 09-19-2007 [eluser]deviant[/eluser] One way to do it is to assign each time a form is loaded it is assigned a random ID that is put in a hidden form field and also in the users session vars as a flash variable (only saved for one page load). When you are processing the form data normally check that the hidden random ID from the forms POST data matches the users session var, if it even exists. That way you will still get the POST data message if you refresh but it will not actually do anything. Preventing double post data being resent - El Forum - 09-19-2007 [eluser]Michael Wales[/eluser] On most all of my forms, I use the same controller for displaying and processing the data, redirecting away upon success. Code: $this->load->library('validation'); A refresh in these circumstances would simply refresh the displayed data. If you are wanting to load a blank form up again, you could always just toss a middle-man in there, like so: Code: $this->load->library('validation'); Kind of a round-about way... Preventing double post data being resent - El Forum - 09-19-2007 [eluser]worchyld[/eluser] I'll try that, thanks... so long as that annoying messagebox doesn't appear again, I'll be happy! |