In your “mental model”, separate the concept of a “page” from a “view” as @philgyford points out.
Think of the views as handling actions or events. Decide what needs to happen for each case.
If I’m understanding what all you’re trying to do here, it looks like you’ve got eight distinct events.
- View 1 - returns a page:
- First form submitted via http post, form is correct.
- First form submitted via http post, form is incorrect.
- View 2 - returns json or html:
- First form submitted via ajax, form is correct.
- First form submitted via ajax, form is incorrect.
- View 3 - returns a page:
- Second form submitted via http post, form is correct.
- Second form submitted via http post, form is incorrect.
- View 4 - returns json or html:
- Second form submitted via ajax, form is correct.
- Second form submitted via ajax, form is incorrect.
If this is a correct summary, then you need to identify what needs to be returned for each of those 8 cases.
After you have that figured out, then you can (if it appears to be desirable) factor out the common code that might be useful as a “utility function”.