Easier form validation with PHP
-
Here’s a class from Simon Willison which allows you to create an easy form generation and validation system for PHP.
Let’s talk about form validation. Here’s what I would class as the ideal validation system for a form in a web application:1. The form is displayed; you fill it in.
2. You submit the form to the server.
3. If you missed something out or provided invalid input, the form is redisplayed pre-filled with the valid data you already entered.
4. The redisplayed form tells you what you got wrong. It also flags the fields that were incorrect.
5. Loop until you fill the form in correctly.Writing this once in PHP is trivial, but takes quite a bit of very dull code. Writing this for more than one form quickly becomes a tedious nightmare of duplicating and slightly editing code, which is why so few forms bother.























