Form validation

August 29, 2011

A friend asked me for some help or pointers on how to implement a form validator, so I spent this afternoon writing some simple code that he could look at for ideas.

The basic concept is reusing the same form for all the data, and if something goes wrong, not to redirect the user with the data, but continue rendering the page.

In other words, instead of exiting a script because of an error, you do it the other way around, if everything is correct, then you exit the script.

Here’s a live preview or you can download the source (formexample (7.4 kB)) instead.

Tags