Form Checking and Displaying Errors

A friend emailed me tonight and asked how I output form errors onto a page once a user has submitted invalid data via a form. Rather than email him back, I’ve posted an abbreviated version of my preferred ‘quick and dirty’ method here.

My friend wrote about 50 lines of code to accomplish what we do in about 10 below. I like this code simply because it allows me to add errors to a complex form when I see the need… and those errors are automatically included in the error array and rendered in a html list (which can easily be formatted). The checks on the form below are there present simply for the purposes of illustrating my point.

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *