Women in Technology

Hear us Roar



Article:
  User-Friendly Form Validation with PHP and CSS
Subject:   NEVER doing any client-side processing is a mistake
Date:   2004-09-25 04:06:11
From:   TimP
It's one thing to bounce a little form with a couple of fields back and forth between a browser and an idle web server. It's another to saddle a user with a screen full on a busy server. I've had that experience as a user, and if I was on a site that I could avoid, I'd just close the browser. As the interactive experience deteriorates because of the constant bouncing of a large complicated form, the slower the server gets. Very unfriendly and very bad for business.


While returning the same form with error messages right on it is the right (although well-known) approach, the friendliness is enhanced by cagey use of both client-side and server-side validation. We have code that keeps the submit buttons inoperative until all manditory fields are completed, the manditory fields are labeled in red as a visual clue, the field content errors are presented field-by-field or as a group depending on the flow of the form, and the server-side processing is limited to protecting the application and the database.


Granted, you'll have to stretch a bit technically if you don't regard JS to be as beloved as PHP. Try O'Reilly's "Javascript: the Definitive Guide". It's probably one of the top two or three books I've bought in the last 4 years. As the head carpenter send to his assistant: "Don't you be bangin' no screws in with that there hammer."