tags:

views:

159

answers:

3

For the successful use case, the Post/Redirect/Get (PRG) work flow is pretty simple: simply redirect (client-side) to the desired page. But what about cases when errors are encountered during server-side validation and we want to preserve the inputs when we display the input page again?

As far as I can tell, there are two approaches: simply re-render the input page after the form POST submission (i.e. no redirection) during errors (thus disregarding the PRG pattern); or, redirect to the input page, and store the previous inputs somewhere it can be retrieved later (e.g. session), during rendering. Both have drawbacks: in the first, we are presented with the problems PRG pattern helps us to avoid (e.g. bookmarkability, double submission); the second approach leads to inconsistent GETs (first GET will find the stored inputs, subsequent GETs might not). Are there other alternatives to those mentioned here? I am hoping for inputs from the community on how this case is best handled.

+1  A: 

If the URL being used to fill out the form is the one the form POSTs to, I don't think there's an issue. If the input is valid, Redirect and GET. If it's invalid, redisplay the filled-in form. This way, the interaction looks like:

GET  /your-url => blank form
POST /your-url (success) => Redirect => GET /success-url
POST /your-url (failure) => filled-in form
Justin Voss
+1  A: 
Willie Wheeler
A: 

But what if you also want to display a success message or some other information like this on final page?

Vijay