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?


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



400 BAD REQUEST - contains populated form HTML with errors

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

POST /example



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.

  • 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?

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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