Why does form validation error not cause redirect and gives a different url?

In phoenix if you input form data and submit it you’ve caused the following workflow

  • GET /posts/new
  • POST /posts

However if the form data is invalid phoenix will render the input form again with error messages but the url in the browser will be /posts instead of /posts/new. It is not a big deal but out of curiosity why is phoenix setup like that?

I think if you want the url not to change you’ll have to instruct that in the router this way:

get "/posts/new", YourController, :new
post "/posts/new", YourController, :create

When you submit your form it is sent to the create action through the url you specified in your router.

as you said it is not a big deal because most of the time the post url is not important since if the form submission is ok, you’ll redirect anyway to some other pasth such as index.