CodeIgniter Forums
Best way to disable going back to form page after user has clicked submit? - 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: Best way to disable going back to form page after user has clicked submit? (/thread-59453.html)



Best way to disable going back to form page after user has clicked submit? - El Forum - 10-06-2013

[eluser]Unknown[/eluser]
Hi guys, I've built a small survey form which will be sent out via email to a list of people. After the user has clicked submit on the "survey form" page, a "thank you" page is displayed. I'd like to make it so that if they click the browser back button the cached "survey form" page is not displayed. Maybe it will say the page has expired or something?

Sorry I'm fairly new to php/codeigniter! Any help would be really appreciated.

Thanks =)


Best way to disable going back to form page after user has clicked submit? - El Forum - 10-07-2013

[eluser]Otemu[/eluser]
This old post has all the answers you seek Smile
http://ellislab.com/forums/viewthread/220867/


Best way to disable going back to form page after user has clicked submit? - El Forum - 10-07-2013

[eluser]Unknown[/eluser]
Thanks for your reply =)

Although I've tried the code mentioned in that topic:

header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:iConfused") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

But the cached "survey form" page is still being displayed after clicking the back button upon viewing the "thank you" page.

What I've noticed the above code does do though is:

If the user fills out the survey, misses 1 or more questions, my validation is run, the page is reloaded with the "Please select an answer!" error message beside each question they've missed, user then fills out the missed field/s, clicks submit, see's the "thank you" page. NOW if the user clicks back, (which would take them to the form with error messages) the "This page has expired" error displays (which is good!) however if the user then clicks back again - they are brought back to the original survey form page.

It's really stressing me out! haha any other suggestions?




Best way to disable going back to form page after user has clicked submit? - El Forum - 10-09-2013

[eluser]boltsabre[/eluser]
You could try setting a session variable after the form is successfully submitted (named, for example, "survey_complete").

Then you can check in your controller functions if it is set, and if so display one view (survey complete page), else display your survey view.

Personally I haven't tried this, but give it a shot, might work. Just make sure you have done the header stuff you've listed above.


Best way to disable going back to form page after user has clicked submit? - El Forum - 10-10-2013

[eluser]bgreene[/eluser]
I had a similar problem (emulating a cancel button and using history.js) and it comes from the fact that each time the users clicks submit, any error will call the form again so if the user makes 2 attempts to submit then the back button effectively has to be clicked twice. The solution i came up with was to block the submit action and verify the form data using ajax before proceeding. this way backclick will always bring you to the form being viewed before the submit form.