PHP
  Home arrow PHP arrow 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 
Actuate Whitepapers 
VeriSign Whitepapers 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Building An Extensible Form Validator Class


    (Page 1 of 12 )

    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

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





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