PHP
  Home arrow PHP arrow Page 3 - Building a PHP 5 Form Processor: Using the Form Processor Package
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? 
Google.com  
PHP

Building a PHP 5 Form Processor: Using the Form Processor Package
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 21
    2006-01-30


    Table of Contents:
  • Building a PHP 5 Form Processor: Using the Form Processor Package
  • Getting started: constructing programmatically an online form
  • Performing server-side validation: implementing the “validator” module
  • Gluing the pieces: putting the form processing modules to work together
  • The complete application at a glance: listing the complete code of the form processor

  • 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 a PHP 5 Form Processor: Using the Form Processor Package - Performing server-side validation: implementing the “validator” module
    ( Page 3 of 5 )

    As you know, in addition to basic client-side validation performed before submitting the form, the “validator” module, which I developed in the previous article, exposes some handy methods for verifying on the server whether user-supplied data is valid or not. It’s precisely for this reason that I’ll write a little piece of code, which validates the data entered in the required fields. The checking script looks like this:

    if($_POST['send']){
        // instantiate form validator object
        $fv=new formValidator();
        $fv->validateEmpty('fname','Enter your first name (Min: 4
    characters)');
        $fv->validateEmpty('lname','Enter your last name (Min: 4
    characters)');
        $fv->validateEmail('email','Enter a valid email address');
        // check for errors
        if($fv->checkErrors()){
            // display errors
            echo '<h2>Resubmit the form after correcting the
    following errors:</h2>';
            echo $fv->displayErrors();
        }
        else {
            echo '<h2>Thank you for submitting your data!</h2>';
        }
    }

    If you study the above script, you’ll see that after submitting the form, a form “validator” object is instantiated, in order to verify the data of each required field. In this example I’ve used the “validateEmpty()” method for checking whether the values entered for “First Name” and “Last Name” are empty strings or not. Similarly, the “email” field is checked by the “validateEmail()” method.

    After running the server-side checking script and assuming that invalid data was submitted by the form, the output might look like this:

    As you can see, the “formValidator” class does a decent job validating the required fields. Of course, the look and feel for displaying error messages should be styled properly, but I guess you have a pretty clear idea of how the server-side validation process works.

    Having demonstrated the nice capabilities of both form processing modules, it’s time to show how they fit into a single script. Considering this situation, jump into the next section to learn how these modules are implemented on the same PHP file.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek