bracketfire Posted November 14, 2013 Share Posted November 14, 2013 Let's say the user submits a form. If I then process the form and return a page, and the user reloads that resultant page, they are hit with the famous "Are you sure you want to resubmit the data" dialog. In other apps I've written, I've avoided this by using the http://en.wikipedia.org/wiki/Post/Redirect/Get (Post Redirect Get / PRG) pattern. Essentially, I handle the CRUD or other database work when processing the POSTed page, then save any necessary values in session and redirect to the same page via a 302 redirect GET. That way the POSTed page doesn't appear in the browser history, and they can reload freely with no side effects, and if they hit BACK they go back to the form and aren't prompted to re-post the data. I'm wondering if others do this and if anyone has any neat processwire-ish ways of handling it. In particular, is it acceptable to save the posted data in session with $session->PRG = $input->post; $session->PRGPAGE = $page->id; so that any values needed in the following screen (to generate a confirmation message, etc) are available from session. In my system Template Files are controllers derived from a base class, so on each subsequent page, if the page doesn't match PRGPAGE, I'd clear the $session->PRG data so it doesn't hang around as the user moves around on the site. Does this make sense? Anyone else doing something like this to avoid POST resubmits? 2 Link to comment Share on other sites More sharing options...
nik Posted November 15, 2013 Share Posted November 15, 2013 Sure it makes sense, especially the redirect part. And there's nothing wrong with saving something to the session either. This is pretty simple stuff and I'm not sure there are too many ways to do it - so no ProcessWire tricks to share. Looks like you've nailed it already, nice and simple. Only thing I haven't tried is saving the whole post data at once into session. And if that didn't work, you could always save individual values instead of the whole structure. So nothing much to say, but didn't want to leave your question unanswered either . 1 Link to comment Share on other sites More sharing options...
bracketfire Posted November 16, 2013 Author Share Posted November 16, 2013 Thanks for this, nik. I also stumbled upon another post today where Ryan talks about the risks of saving $input->post to session, directly. http://processwire.com/talk/topic/1128-session-problem/ Essentially, he argues to store only what you need, after sanitizing it. I tend to agree and will go that route. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now