Old School Validation
If you’re working on a team, you may have a PHP developer. She’ll write the code that captures the data, validates it, and stores it in the database. She may have done a similar process to what you just did. She may be using a code library that has done the heavy lifting for her. Here’s to hoping – Cheers! Her test data sufficiently passed the tests she thought up, and committed to subversion for the next website update.
What Could Go Wrong?
What’s wrong with the scenarios above? There’s a couple of things, actually.
A Better Way
The solution is one of mindset. Progressive Enhancement is your friend. By doing the following you’ll create a better user experience, and save yourself a lot of time and frustration.
Start with HTML. When you layout your form, consider which fields are required. For each field that’s required, create the appropriate markup and css for an error message. Then talk with your PHP developer about your required fields and your expectations about how they should be validated. It’s up to her to create a function that examines all the inputs on the server. She’ll use that function to return an array of errors. It’s important that the validation logic to be in a separate function. She’ll repopulate the form with the pertinent error messages next to each field. The styles used will be what you designed earlier.