Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In the field of web development, is it good practice to do a POST/Redirect/GET when fields in a form submission are invalid, as well?

Typically, no sensitive transaction would have taken place, in this event. However, can an argument be made that, nonetheless, it is still good practice to utilize the POST/Redirect/GET pattern?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

From a REST perspective the web conversation should go like this

GET /example

200 OK - contains empty form HTML

The user fills in the form

POST /example

formfield1=ok

formfield2=bad

400 BAD REQUEST - contains populated form HTML with errors

The user identifies the problem with the form submission and fixes it

POST /example

formfield1=ok

formfield2=fixed

201 CREATED - contains HTML with success message and onward links (also Location header for REST clients) or 200 OK and 204 NO CONTENT are acceptable

There is no need to introduce a redirect, and it would break the semantics of the conversation to do so.

share|improve this answer
1  
O wow, yeah, how could I have forgotten about REST, or just different HTTP status codes in general. I had a brain fart when asking this question. Thanks! –  Decent Dabbler Jan 31 '13 at 21:25
1  
The redirect in the PRG pattern, though, is there due to an admission that maintaining the "semantics of the conversation" is less important than preventing ham-fisted users from mashing F5 and ignoring the "that will resubmit the form.." warning from their browser. –  Carson63000 Feb 2 '13 at 7:44
    
Fair enough, which is why I mentioned the REST perspective. –  Gary Rowe Feb 2 '13 at 17:07

I would say generally not, on the grounds that when a form is POSTed with invalid fields, what you normally want to serve in response is the same form with the same field population, plus some error messages. This would be onerous to perform via POST/Redirect/GET - how would you ensure that the page returned by the GET already had the user's entries in the form fields?

share|improve this answer
2  
By temporarily storing the result in a session (for the duration of one follow-up request)? –  Decent Dabbler Jan 31 '13 at 3:38
2  
@fireeyedboy: yep, that would do it.. seems a bit of a kludge though. –  Carson63000 Jan 31 '13 at 5:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.