Design Usability
  Home arrow Design Usability arrow Page 2 - 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  
Moblin 
JMSL Numerical Library 
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? 
DESIGN USABILITY

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

    Table of Contents:
  • Using HTML_QuickForm To Manage Web Forms, Part 2
  • Hierarchical Drop Downs in Web Forms
  • Auto-complete Text Boxes
  • Dressing Up Your Web Form
  • Getting Smart with HTML_QuickForm
  • End Game
  • 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


    Using HTML_QuickForm To Manage Web Forms, Part 2 - Hierarchical Drop Downs in Web Forms


    (Page 2 of 7 )

    Consider this: I need my Web form (from the first article) to display two drop downs - one containing "Artist Type" and the second, the "Artist Sub-type". However, the options displayed in the second drop down have to be dynamically updated depending on the value selected in the first.

    Normally, I resort to complex client-side scripting to implement such requirements. Not any more because the HTML_QuickForm comes with a custom "hierselect" control that does all this behind-the-scene jugglery for me.

    Not convinced? Take a look at the following code listing:

    Code Listing 1

    Save this script and load it in the browser:

    Using HTML_QuickForm

    Now, select a different option from the first "Artist Type" drop down to see the options of the second drop down update automatically:

    Using HTML_QuickForm

    Now, review the following code segment:

    <?php

    require_once 'HTML/QuickForm.php';

    // snip

    // snip - some fields have been removed in order to avoid repetition

    // define artist types
    $ary_artist_type[0] = 'Solo';
    $ary_artist_type[1] = 'Group';

    // define artist sub-types
    $ary_artist_sub_type[0][1] = 'Male';
    $ary_artist_sub_type[0][2] = 'Female';
    $ary_artist_sub_type[1][3] = 'Males Only';
    $ary_artist_sub_type[1][4] = 'Females Only';
    $ary_artist_sub_type[1][5] = 'Male and Female';

    $obj_hdd_artist_type = &$obj_registration_form->addElement('hierselect', 'ddlArtistType', 'Select Artist Type:', '', '<br />');

    // set option arrays for "Artist Type" hierarchical <SELECT> drop down
    $obj_hdd_artist_type->setOptions(array($ary_artist_type,  $ary_artist_sub_type));

    // snip

    ?>

    After importing the required PEAR class files, I have created a local instance of the HTML_QuickForm() object. Then, I fall back on the resourceful addElement() method to insert the different <FORM> elements.

    However, before I can add my new "hierarchical" drop down control, some groundwork has to be done: the definition of two arrays - "$ary_artist_type" containing the options for the "Artist Type" drop down and "$ary_artist_sub_type" for the "Artist Sub-type" drop down.

    Next, I invoke the addElement() method, passing the "hierselect" keyword as an input parameter. This instructs the HTML_QuickForm() object to create an instance of the HTML_QuickForm_hierselect() object - responsible for the rendering of hierarchical drop downs in the output. Lastly, I have used the setOptions() method to populate the options of the two drop downs.

    Note that if I wish to render a three level hierarchy, I’ll have to define three arrays and so on.

    Next, I have added an "advanced checkbox" control. By default, a Web form does not post any value if a checkbox element is not "checked." The onus of taking a decision, of whether checkbox is "checked" or not, lies with the programmer. Not so, if I use the "advanced checkbox" control - this custom control will always post a value. Take a look at the next code fragment:

    <?php

    // snip

    $obj_registration_form->addElement('advcheckbox', 'chkNewsletter', 'Subscribe to Newsletter:', 'Yes', null, array('No', 'Yes'));

    // snip

    ?>

    The "advcheckbox" keyword instructs the HTML_QuickForm() object to render an "advanced checkbox" control. The values to be POSTed are passed in the form of an array - the first is passed when the box is not "checked" and the second, when the box is "checked."

    Finally, I’d like you to take another look at an upated version of the "date" control:

    <?php

    // snip

    $obj_registration_form->addElement('date', 'txtDateOfBirth', 'Date of Birth:', array('format' => 'dFY', 'addEmptyOption' => 'true', 'emptyOptionValue' => '', 'emptyOptionText' => 'Select'));

    // snip

    ?>

    Here, I would like to highlight the use of the "format" attribute - as the name suggests, this allows me to specify the format for the "date" control. The string "dFY" is consistent with the format string used with the date() PHP function. For more "format specifiers," please review the HTML_QuickForm documentation.

    For the same control, I have listed three additional attributes: "addEmptyOption" informs the renderer to add an empty <OPTION> at the beginning of the drop down, "emptyOptionValue" allows me to specify the value for this <OPTION> (I’ve set this to a blank string) and the "emptyOption" attribute contains the text that is displayed (I’ve set this to "Select").

    In the next section, I’ll show you how to render "auto-complete" text boxes - a common feature in most PC-based applications, but a challenge to implement for browser-based ones.

    More Design Usability Articles
    More By Harish Kamath


       · so I am the first, now what ?
       · Thanks for the articles, I took at look at HTL_QuickForm about 12 months ago and...
       · For part three.what about quickform controllers and dynamic renderers? What...
       · Thanks for a very helpful tutorial, exactly what I was looking for. I had an old...
     

    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 3 hosted by Hostway