PHP
  Home arrow PHP arrow Page 4 - Building An Extensible Form Validator ...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building An Extensible Form Validator Class
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 39
    2002-03-27

    Table of Contents:
  • Building An Extensible Form Validator Class
  • Back To Class
  • The Bare Bones
  • How Things Work
  • Private Eye
  • Running On Empty
  • Floating Like A Butterfly
  • Mail Dot Com
  • Under Construction
  • A Quick Snack
  • Going To The Source
  • Closing Time

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building An Extensible Form Validator Class - How Things Work


    (Page 4 of 12 )

    Now, before proceeding further, I need to decide how this class is going to work. Here's how I plan to use it:

    <?php // some form processor // let's assume that the variables $a and $b // have been obtained via a form POST operation // create an object $fv = new FormValidator(); // run validation methods // the first argument is the name of the field to validate // the second is the error to report if validation fails $fv->isString("a", "Please enter a string for field A"); // same here $fv->isNumber("b", "Please enter a string for field B"); // check to see error status echo $fv->isError(); ?>
    As you can see, I would like to call class methods with two parameters: the name of the form variable to validate, and the error message to return in the event the validation test fails. With this in mind, it becomes much easier to design the class appropriately.

    Once the basic functionality of the class is clear, it's a good idea to spend some time listing the important methods, together with their purpose. Here's my initial cut:

    isEmpty($var, $errormsg) - check whether the specified form variable is empty;

    isString($var, $errormsg) - check whether the specified form variable contains string data;

    isNumber($var, $errormsg) - check whether the specified form variable contains numeric data;

    isWithinRange($var, $errormsg) - check whether the specified form variable contains a value within the specified numeric range;

    isEmailAddress($var, $errormsg) - check whether the specified form variable contains a valid email address;

    isError() - check whether any errors have occurred in form validation;

    getErrorList() - return the list of validation errors;

    resetErrorList() - reset the error list.

    These are the essential methods; there may be more, which I will add as development progresses.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway