Home arrow PHP arrow Page 3 - Building An Extensible Form Validator Class

The Bare Bones - PHP

Wondering what OOP can do for you? Well, wonder no more - thisarticle demonstrates how OOP can save you time and effort by building aPHP-based Form Validator object to validate HTML form input. In additionto a detailed walkthrough of the process of constructing a PHP class totest user input, this article also includes usage examples and a brieflook at some powerful open-source alternatives.

TABLE OF CONTENTS:
  1. Building An Extensible Form Validator Class
  2. Back To Class
  3. The Bare Bones
  4. How Things Work
  5. Private Eye
  6. Running On Empty
  7. Floating Like A Butterfly
  8. Mail Dot Com
  9. Under Construction
  10. A Quick Snack
  11. Going To The Source
  12. Closing Time
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 54
March 27, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
So that's the theory. Let's now spend a few minutes discussing the rationale behind the FormValidator object I plan to build.

Stripped down to its bare bones, my FormValidator class consists of two components:

1. A series of methods that accept the data to be validated as method arguments, test this data to see whether or not it is valid (however "valid" may be defined within the scope of the method), and return an appropriate result code.

2. A PHP structure (here, an associative array) that holds a list of all the errors encountered during the validation process, and a series of methods to manipulate this structure.

As you will see, these two basic components make it possible to build a very simple (and yet very useful) FormValidator object, one that exposes a number of generic methods. It's important to note, however, that these methods will have nothing to do with the visual presentation of either the form or the form's result page; rather, they provide a simple API to perform validation of the data entered into the form, and are designed for use by server-side scripts which are more closely connected to the presentation layer.

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap

Dev Shed Tutorial Topics: