JavaScript
  Home arrow JavaScript arrow Page 3 - Adding Server-side Capabilities to Form Va...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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? 
JAVASCRIPT

Adding Server-side Capabilities to Form Validation with the DOM
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2006-11-07

    Table of Contents:
  • Adding Server-side Capabilities to Form Validation with the DOM
  • A quick look at the previous form validation script
  • Adding server-side capabilities to the original application
  • Completing the form validation class
  • Assembling the client and server-side modules of the application

  • 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


    Adding Server-side Capabilities to Form Validation with the DOM - Adding server-side capabilities to the original application


    (Page 3 of 5 )

    In simple terms, the form validation class that I plan to develop here is really easy to grasp. It should also be familiar to you, since I’ve been using it in some of my previous PHP tutorials. If this doesn’t ring any bells to you, here is the partial signature of this new class, which has some helpful methods aimed at validating different types of data:

    class FormValidator{     private $errors=array();     private $method;     const MIN=4;     const MAX=32;     public function __construct(){         $this->method=$_POST;     }     // validate empty values     public function validateEmpty($field,$errorMessage){         if(!$this->method[$field]||trim($this->method[$field])
    ==''||strlen($this->method[$field])<self::MIN||strlen($this->
    method[$field])>self::MAX){             $this->errors[]=$errorMessage;         }     }     // validate integer values     public function validateInt($field,$errorMessage){         if(!$this->method[$field]||!is_numeric($this->
    method[$field])||intval($this->method[$field])!=$this->method[$field]){             $this->errors[]=$errorMessage;         }     }     // validate numeric values     public function validateNumber($field,$errorMessage){         if(!$this->method[$field]||!is_numeric($this->method[$field])){             $this->errors[]=$errorMessage;         }     }     // validate range of values     public function validateRange($field,$errorMessage){         if(!$this->method[$field]||$this->
    method[$field]<self::MIN||$this->method[$field]>self::MAX){             $this->errors[]=$errorMessage;         }     } }

     

    For this concrete case, the “FormValidator” class shown above presents a few simple methods which come in handy for performing strong validation on the data entered in a given web form. As you can see, the aforementioned class is capable of checking for empty strings, numeric and alphabetic values, predefined ranges of data, and so forth.

    Logically, due to its extreme versatility, the previous class can be easily improved to extend its functionality even more. Considering this, in the next few lines I’ll be adding some extra methods to the referenced class so it can be used in conjunction with the DOM-based validation script that you learned in previous tutorials.

    Sounds really interesting, right? So go ahead and read the following section.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this final part of the series, the original form validation application is...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT