CodeIgniter Forums
prevent re-inserting data. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: prevent re-inserting data. (/thread-57354.html)



prevent re-inserting data. - El Forum - 03-08-2013

[eluser]ede196620[/eluser]
Hello everyone i new to codeigniter currently i am working on my first project yes i am still a noob Smile my question is what methods are there in preventing double submissions on a form ? tnx for your posts in advance.


prevent re-inserting data. - El Forum - 03-08-2013

[eluser]TheFuzzy0ne[/eluser]
As soon as validation passes, I like to redirect the user to another location. This prevents double submissions.

Code:
redirect('/some_controller/form_success');



prevent re-inserting data. - El Forum - 03-08-2013

[eluser]ede196620[/eluser]
Tnx for posting . I did think of this but the user can click the back button and submit the form again do u have any other suggestions ? i found out about Post/Redirect/Get method and trying to look in to that.


prevent re-inserting data. - El Forum - 03-08-2013

[eluser]TheFuzzy0ne[/eluser]
Are you simply wanting to prevent the user from accessing that form again, or to stop them submitting it again with the back button?

I've redirected for years, and it works for me. I see no reason why it shouldn't work for you. The back button just takes the user back to the form, it does NOT resubmit it if you redirect after you've saved the data to the database.


prevent re-inserting data. - El Forum - 03-08-2013

[eluser]Otemu[/eluser]
Hi,

I use the method TheFuzzy0ne said and I haven't had any issues.
The main thing is that you have validation checks, for instance if a user registers to your site and refreshes the page, then your validation should check if a user exists before it does any insert. Now instead of getting the same record inserted into the database the user will get an error.

Another method is to use sessions to store unique id for each form and then process if the id matches.