PHP
  Home arrow PHP arrow Building An Extensible Form Validator Class
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 43
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
    ( Page 1 of 12 )

    Wondering what OOP can do for you? Well, wonder no more - this article demonstrates how OOP can save you time and effort by building a PHP-based Form Validator object to validate HTML form input. In addition to a detailed walkthrough of the process of constructing a PHP class to test user input, this article also includes usage examples and a brief look at some powerful open-source alternatives.One of my most common activities during the development cycle for a Web application involves writing code to validate the data entered into online forms.

    This might seem like a trivial task, but the reality - as anyone who's ever spent time developing a robust Web application will tell you - is completely different. Data verification is one of the most important safeguards a developer can build into an application that relies on user input, and a failure to build in this basic error checking can snowball into serious problems (and even cause your application to break) if the data entered is corrupt or invalid.

    In order to illustrate this, consider a simple example, culled from my own experience: an online loan calculator that allows a user to enter the desired loan amount, finance term and interest rate. Now, let's assume that the application doesn't include any error checks. And let's also suppose that the user decides to enter that magic number, 0, into the term field.

    I'm sure you can imagine the result. The application will perform a few internal calculations that will end in it attempting to divide the total amount payable by the specified term - in other words, division by zero. The slew of ugly error messages that follow don't really bear discussion, but it's worth noting that they could have been avoided had the developer had the foresight to include an input-validation routine while designing the application.

    The things about data validation, though, is that it's one of those things you can't hide from. Even if you develop and release a Web application without building in any validation routines (either through ignorance or laziness), you can be sure that your customer's going to demand a fix for it in the next release of the software. And since - as I said right at the beginning of this article - it's one of the few things you're likely to do over and over again when building Web applications, it's worthwhile spending a little time to make the process as painless as possible.

    That's where this article comes in. Over the next few pages, I'll be attempting to build a reusable library of functions for form input validation, in an attempt to save myself (and, hopefully, you) some time the next time an application needs to have its input checked for errors. The end result of this experiment will be a PHP class that can be easily included in your scripts, and that exposes basic object methods for data validation. It may not meet *all* your needs; however, the process should be instructive, especially if you're new to object programming in PHP, and you'll have very little difficulty customizing it so that it works for you.

    Let's get going!

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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT