Design Usability
  Home arrow Design Usability arrow Page 11 - Using HTML_QuickForm To Manage Web Forms, ...
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  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 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? 
DESIGN USABILITY

Using HTML_QuickForm To Manage Web Forms, Part 1
By: Harish Kamath
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 48
    2004-12-22

    Table of Contents:
  • Using HTML_QuickForm To Manage Web Forms, Part 1
  • Installing The HTML_QuickForm Package
  • My First HTML_QuickForm
  • FORM Elements
  • Adding Standard HMTL FORM Elements
  • Defining FORM Controls, Submitting Data
  • Grouping
  • "Checkbox" and "Radio" Elements
  • Drop Down Control and Hidden Element
  • Implementing Form Validations
  • Password Field Validation
  • Processing Data With HTML_QuickForm
  • Conclusion

  • 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

    Using HTML_QuickForm To Manage Web Forms, Part 1 - Password Field Validation


    (Page 11 of 13 )

    Note that I have added some text field to my Web form to demonstrate another common validation requirement - the comparison of text entered in two "password" fields.

    <?php

    // snip

    $obj_registration_form->addElement('text', 'txtUsername', 'Username:', array( 'size' => 40, 'maxlength' => 15));

    $obj_registration_form->addElement('password', 'txtPassword1', 'Password:', array( 'size' => 40, 'maxlength' => 15));

    $obj_registration_form->addElement('password', 'txtPassword2', 'Re-enter Password:', array( 'size' => 40, 'maxlength' => 15));

    // snip

    $obj_registration_form->addRule('txtPassword1', 'Please enter your "Password" as it is a required field.', 'required');

    $obj_registration_form->addRule(array('txtPassword1', 'txtPassword2'), 'The two passwords do not match. Please re-enter your password correctly.', 'compare');

    $obj_registration_form->addRule('txtPassword1', 'Please enter a valid "Password" containing between 8 and 10 consisting of alphabets and numbers only.', 'regex', '/^[a-zA-Z0-9]{8,10}$/');

    // snip

    ?>

    Here, I have added three new text fields: one for the user to enter his/ her username and two password fields to ensure that the user enters the password correctly. This is a common feature for most Web forms.

    Next, I would like to highlight the "compare" keyword. This new rule allows me to compare the values entered into any two text fields. All I need to do is pass the names of the two controls to the addRule() method.

    Here is the error message displayed on the screen if the user enters two different values in the "Password" and "Confirm Password" fields.

    Using HTML_QuickForm

    The above example has implemented server-side validation for all the fields of the Web form. However, it is also possible to implement client-side with a little modification to the above example:

    Code Listing 4

    Load this example in your browser and click the "Register" button with filling any form field. The browser will immediately throw a JavaScript alert as seen below:

    Using HTML_QuickForm

    This client-side validation is, courtesy of, a simple update to each validation rule defined in our earlier script:


    <?php

    // snip

    // validation rules come here
    $obj_registration_form->addRule('txtAddress', 'Please enter your "Address" as it is a required field.', 'required', null, 'client');
    $obj_registration_form->addRule('txtAddress', 'Please enter at least 20 characters in the "Address" field.', 'minlength', 20, 'client');
    $obj_registration_form->addRule('txtAddress', 'Please enter at most 255 characters in the "Address" field.', 'maxlength', 255, 'client');

    // snip

    ?>

    The fifth parameter of the addRule() method is used to specify the location where I wish to check the validations. This parameter takes two values: the first is "server" -  the default value - and the second is "client."

    A little point to keep in mind: server-side is always performed. This ensures that validations are still implemented if a user has turned off JavaScript in his/her browser.

    So far, this class has met my requirements as defined at the beginning of this article. Now, all that remains to be seen is how to store the data submitted by the user into a database, which is the final step for most Web form applications.

    More Design Usability Articles
    More By Harish Kamath


       · When first time i saw this article i thought that it will solve all my problems that...
     

    DESIGN USABILITY ARTICLES

    - Create Great JavaScript and CSS Menus Simply
    - Design Principles that Shape a Web Site
    - Creating Aqua Style Images
    - Easy as A,B,C – dynamic A to Z indexes
    - EasyChart: a Usability Teaching Tool to Demo...
    - Building Friendly Pop-up Windows
    - Back to School: Design Usability
    - Using HTML_QuickForm To Manage Web Forms, Pa...
    - Using HTML_QuickForm To Manage Web Forms, Pa...
    - More Website Knick Knack
    - Browsers as Test Platforms
    - Website Knick Knack
    - Dynamic Page Elements-Cloak and Dagger Web D...
    - Accessibility and Dreamweaver MX 2004







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