Graphic Design
  Home arrow Graphic Design arrow Page 10 - Using HTML Quickform for Form Processing
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 
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? 
GRAPHIC DESIGN

Using HTML Quickform for Form Processing
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 160
    2004-09-01

    Table of Contents:
  • Using HTML Quickform for Form Processing
  • Steps for the Example
  • Individual Elements
  • Text, Password, Textarea
  • Hidden, Select
  • Checkbox, Radio
  • Submit, Reset, Button, Image
  • File, advcheckbox, Static
  • Header, Link, HTML
  • Element Groups
  • Processing Submitted Data
  • Without a Callback Function
  • Setting Validation Rules

  • 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 for Form Processing - Element Groups


    (Page 10 of 13 )

    You can present elements in groups with HTML_QuickForm. This changes their layout. Instead of each element having its own label and table row, all the elements in a group are displayed in the same table row. They share a label. To group elements, first create each of them using the createElement() method. Store the created elements in an array. Then, add the group of elements to the form by passing the array to the addGroup() method. For example, here’s how to create a group of three text fields:

    $name[] = &HTML_QuickForm::createElement('text','firstname');
    $name[] = &HTML_QuickForm::createElement('text','middlename'); $name[] = &HTML_QuickForm::createElement('text','lastname');
    $form->addGroup($name,'user_name','Your Name: ',' ');

    This adds the following HTML to the form:

    <tr>
    <td align="right" valign="top"><b>Your Name: </b></td>
    <td valign="top" align="left"><input name="user_name[firstname]" type="text"
    /> <input name="user_name[middlename]" type="text" /> <input name="user_name[lastname]" type="text" /></td>
    </tr>

    Each call to createElement() adds another element to the $name array. You can specify null for arguments such as label when you call createElement() because these elements take their label from the group.

    The first argument to addGroup() is the array of elements that make up the group. The second argument is the name of the group, and the third argument is the single label used for the entire group. The individual element names in the HTML are constructed from the group name passed to addGroup() and the element name passed to createElement(). The group is treated as an array, and each text field is an element of that array. This results in individual element names of user_name[firstname], user_name[middlename], and user_name[lastname].

    The <input type="text"> HTML tags for each element of the user_name group are separated by a space because the third argument to the addGroup() call is aspace. Specify any string to separate the elements by passing it to addGroup(). For phone numbers, a hyphen is a good separator:

    $phone[] = &HTML_QuickForm::createElement('text','areacode',null,'size="3"');
    $phone[] = &HTML_QuickForm::createElement('text','exchange',null,'size="3"');
    $phone[] = &HTML_QuickForm::createElement('text','last4',null,'size="4"');
    $form->addGroup($phone,'phone_number','Phone: ','-');

    This group displays the following HTML:

    <tr>
     <td align="right" valign="top"><b>Phone: </b></td>
     <td valign="top" align="left"><input size="3" name="phone_number[areacode]" type="text" />-<input size="3" name="phone_number[exchange]" type="text" />-
    <input size="4" name="phone_number[last4]" type="text" /></td>
    </tr>

    In addition to using -as the element separator, this example passed attributes to createElement() as a fourth argument. These attributes adjust the size of each text field. The third argument, where a label would go, was left as the empty string. You can also use HTML as a group element separator. For example, make the group element separator to display a line break between each element in the group.

    Grouping Radio Buttons

    Creating a group of radio buttons with the same name but different values requires a slightly different syntax. The radio buttons should be created with no name or label, just text and value. For example, the following are three radio buttons in a group, each corresponding to one meal:

    $meals[] =& HTML_QuickForm::createElement('radio',null,null,'Breakfast','br');
    $meals[] =& HTML_QuickForm::createElement('radio',null,null,'Lunch','lu');
    $meals[] =& HTML_QuickForm::createElement('radio',null,null,'Dinner','di');
    $form->addGroup($meals,'meal','Meal: ','<br>');

    Because each of the radio buttons in the group have no name of their own, they each take their name from the group name: meal. They have identical names but different values. Only one of the values is submitted with the form. For example, if the Breakfast radio button is selected, then the submitted form variable meal has the value br. The following is what the HTML looks like for this group of radio buttons:

    <tr>
    <td align="right" valign="top"><b>Meal: </b></td>
    <td valign="top" align="left"><input value="br" type="radio" id="qf_a8704d"
    name="meal" /><label for="qf_a8704d">Breakfast</label><br>
    <input value="lu" type="radio" id="qf_39a433" name="meal" /><label
    for="qf_39a433">Lunch</label><br>
    <input value="di" type="radio" id="qf_c5fabd" name="meal" /><label
    for="qf_c5fabd">Dinner</label></td>
    </tr>

    This chapter is from Essential PHP Tools: Modules, Extensions, and Accelerators, by David Sklar, (Apress, 2004, ISBN: 1590592808). Check it out at your favorite bookstore today.

    Buy this book now.

    More Graphic Design Articles
    More By Apress Publishing


       · Any idea what version this comes in for the PEAR distribution?
       · If you follow the example code for uploading a file you may get frustrated that the...
       · Sorry,but I'd rather work in the old fashion way. You have much more control...
       · I think page 13 of the article, "Using HTML Quickform for Form Processing - Setting...
       · it's a really good tutorial. thank you again
       · Good intro, but you don't seem to have anything about setting default values, which...
       · Of course there is a method to set default values:e.g....
       · can you give me an example re: the client-side validation on custom rule.. the...
       · rangelength is not used as a string use array() for the 2 range numbers.ex, a 2...
     

    GRAPHIC DESIGN ARTICLES

    - Building Corner Effects with Transparent Bac...
    - 3D Graphics Technology: VRML Part I - Introd...
    - Creating Visual Effects
    - Web Page Design Overview
    - Creating Artistic Photographs
    - Working with Tools in Paint Shop Pro 8
    - Using HTML Quickform for Form Processing
    - Introduction to Adobe FrameMaker
    - WebLogic Workshop, WebLogic Platform, and th...
    - Planning the Site
    - Working with Web Services
    - WebLogic Workshop Application Development Ba...
    - Scanning Images for Web Use
    - Web Graphics Overview
    - The Pen is Mightier than the Brush Tool







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT