I am working on a web application that involves the user filling out a multi-step form that spans several pages. The form has tabbed navigation across the top (these links do not submit the current page) and a next button at the bottom (which does submit). I am considering several strategies for handling form submission/validation:
one action method and view per form page. When you hit next, it submits the form to the action method for the next page. If there are validation errors, you are redirected back to the previous page:
- URL's are descriptive and can be copy-pasted
- Only redirects in the error case
- Since the redirect does not have the form data, we lose context about the submission which makes it hard to display certain error messages
- The same validation logic works for redirecting the user if they try to visit a step in the flow that they aren't ready for yet
one action method and view per form page. When you hit next, it submits the form to the current page action. If there are validation errors, the same view is returned. Otherwise, we redirect to the next page action:
- URL's are descriptive and can be copy-pasted
- Redirects are very common (not sure if this is bad)
- When displaying validation errors, we are in the same request as the form submission so we have full access to the invalid input
- Have to pass additional context if we want the ability to, for example, add a "Previous" button which also submits
one action method for ALL pages. URL's contain additional context about the step being submitted (e.g.
MyController/MyAction/{step}
). The controller message selects which view page to return depending on validation and the current step.- URL's are not descriptive (e. g. if I submit step 1 to go to step 2, then the URL the user sees will be the same regardless of whether page 1 (invalid) or page 2 is returned
- No redirects
- When displaying validation errors, we are in the same request as the form submission so we have full access to the invalid input
A different method I haven't listed here
I have tried to enumerate what I see as some of the pros and cons of each method, but I would be interested to know:
- What are other pros and cons of these methods? Are mine correct? Could some of the cons I've listed be designed around?
- Is there a standard approach to this problem which I should be using? If so, why is it the standard approach?