Handling invalid Survey submissions
We've already coded the view that handles survey submission to re-display the page with errors instead of processing the results, if any errors are found in the submitted forms. On the display side, since we are using the as_p
convenience method for displaying the form, it will take care of displaying any errors in the forms. So, we should have no code or template changes to make in order to see what happens when an invalid survey is submitted.
What would make a survey submission invalid? The only likely error case for our QuestionVoteForm
is if no answer is chosen. What happens, then, if we attempt to submit a survey with missing answers? If we try it, we see that the result is not ideal:
There are at least two problems here. First, the placement of the error messages, above the survey questions, is confusing. It is hard to know what the first error message on the page is referring to, and the second error looks like it is associated with the first question...