![]() |
Reload Problem, user tend to submit data twice - 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: Reload Problem, user tend to submit data twice (/showthread.php?tid=3904) |
Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]iive[/eluser] I have gone through the user guide about <a href="http://ellislab.com/codeigniter/user-guide/libraries/validation.html">validation</a> and I found that if we submit the form back to the same function in our controller and if user press F5 or Reload Button in their browser, it tends to insert the record twice into db... Any solution to avoid this issue? as user might just click yes to resubmit the POST data again on the browser warning dialog. Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]xwero[/eluser] Before you validate you could check if the same input is already inserted Code: //model You could even make a ajax validation for this. Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]Référencement Google[/eluser] There is a way to do giving a unique ID to the submited form (in a hidden field for exemple, and generated by a microtime function) Then you have to check that the unique ID wasn't already submited. Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]phester[/eluser] Possibly redirect the user to a different page after the form is validated and inserted? Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]Référencement Google[/eluser] redirecting is one step, but this do not prevent the user to hit the back buttun of the browser and submit the form again, that's why the real unique solution is with a unique ID on the submited form. Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]xwero[/eluser] The unique id has to be stored so you have add a field to the database with no meaning once the form is submitted and they have moved on. Or am i seeing this wrong? Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]Référencement Google[/eluser] I never done it, only read some discussions about this in the past, but I would personally try with sessions variable to do this. If I can find again the forum thread wich was explaining how to do it, I will post here. Reload Problem, user tend to submit data twice - El Forum - 10-28-2007 [eluser]iive[/eluser] what I am doing now is using redirect technique.. I have a processing function in my controller and after we have validated and done all the db queries then this function will redirect the user to formDisplay function which display the form(with errors if any). Basically, my form's action will pass to the processing function instead of the formDisplay to do all the validation and processing. Reload Problem, user tend to submit data twice - El Forum - 10-29-2007 [eluser]obiron2[/eluser] I have the same problem, and I am interested to understand how reridcting to the processing rather than the display avoids the issue. You will still be submitting data. As already stated, using a hidden field requires that the hidden value be stored and validated which can be made generic but still has to be called explicity each time you want to save data. Is there any other way to avoid this? Reload Problem, user tend to submit data twice - El Forum - 10-29-2007 [eluser]iive[/eluser] hi obiron2, here is what I do but I wonder my approach is good or not.. let's say I am doing a login form.. I have 1 controller called User.. and there are 2 functions inside... a) function login (will call a view which display the login form) b) function processLogin (will do the validation and process the login) Once the user submit the form, the form will proceed to user/processLogin and we have validation rules there. If the use failed on our validation rules, processLogin function will capture the errors inside CI's validation object and store them into session then it redirects user back to login function. login function will capture the errors in the session and display the form... That is what I am doing now to avoid the reload problem... I hope you can get what I mean |