Graphic Design
  Home arrow Graphic Design arrow Page 5 - Using HTML Quickform for Form Processing
IBM developerWorks
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 
Moblin 
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? 
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 / 147
    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

    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 for Form Processing - Hidden, Select


    (Page 5 of 13 )

      

    The hidden element produces an HTML <input type="hidden"> tag. The browser doesn’t display any input widget when it sees this tag. Hidden elements are useful for passing values from page to page in a form. Remember, though, that a user can see the value of a hidden element by viewing the source code to a Web page. They are displayed without a label or other formatting.

    These are the valid arguments when creating a hidden element:

    • $elementName: The name attribute of the element’s <input> tag.

    • $elementValue: The default value to use for the element. This is overridden by a submitted form value.

    • $attributes: Arbitrary element attributes, as a string or an associative array.

    The following is a sample usage:

    $form->addElement('hidden','code',120374);

    This is the sample HTML:

    <input name="code" type="hidden" value="120374" />

    select

    The select element produces the drop-down box displayed by the HTML <select> tag.

    These are the valid arguments when creating a select element:

    • $elementName: The name attribute of the element’s <input> tag

    • $elementLabel: The label of the element in the form

    • $options: An array holding choices to display in the menu

    • $attributes: Arbitrary element attributes, as a string or an associative array

    The following are its methods:

    setMultiple(): This sets the multiple attribute, which controls whether the user can select more than one element from the menu.

    getMultiple(): This gets the value of the multiple attribute.

    setSelected(): This sets an array containing the selected value or values from the menu.

    getSelected(): This gets the array of selected values from the menu.

    setSize(): This sets the size attribute, which controls how many options to display at once if multiple is set.

    getSize(): This gets the value of the size attribute.

    getPrivateName(): This returns the element name as displayed in the  form. When multiple is set, this is the result of getName() with []  appended to it.

    addOption($text, $value, $attributes): This adds an option to the end of the element’s menu. The $attributes argument is optional.

    loadArray($arr, $values): This adds the options in the associative array $arr to the end of the element’s menu. The values of the new options are taken from the keys of $arr. The text of the new options is taken from the values of $arr. The optional $values argument holds an array or comma-separated string of values to set as selected in the menu. For example:

    $s =& $form->createElement('select','animal','Animal: ');
    $opts = array('dog' => 'woof', 'cat' => 'meow', 'cow' => 'moo');
    $s->loadArray($opts,'cat');
    $form->addElement($s);

    The menu is displayed with the following HTML:

    <tr>
    <td align="right" valign="top"><b>Animal: </b></td>
    <td valign="top" align="left"><select name="animal">
    <option value="dog">woof</option>
    <option value="cat" selected="selected">meow</option>
    <option value="cow">moo</option>
    </select></td>
    </tr>

    loadDbResult($result, $textCol, $valueCol, $values): This adds options from the PEAR DB DB_Result object to the end of the element’s menu. The $textCol argument holds the name of the column in the DB_Result object to use as the text of each option, and the $valueCol argument holds the name of the column to use as the value of each option. Both $textCol and $valueCol are optional. If they are omitted (or NULL), then the text of each option is the first column in the DB_Result object, and the value of each option is the second column. As in loadArray(), the optional $values argument holds an array or comma-separated string of values to set as selected in the menu.

    loadQuery($conn, $sql, $textCol, $valueCol, $values): This runs a database query and adds options from the query results to the end of the element’s menu. The $conn argument is either a valid PEAR DB database connection handle or a string containing a PEAR DB Data Source Name (DSN). If $conn is a connection handle, then the SQL query in $sql is sent to the database using that connection handle. If $conn is a DSN, then a connection is established using the DSN, and the query in $sql is sent to the database using that new connection handle. The optional $textCol, $valueCol, and $values arguments behave as they do in the loadDbResult() method. Because loadQuery() accepts its first argument by reference, you can’t pass a DSN as a string literal but must instead pass a variable that holds the DSN. For example:

    // The right way to do it
    $dsn = 'mysql://user:password@host/db';
    $s->loadQuery($dsn,'SELECT flavor,id FROM ice_cream');
    // The wrong way to do it:
    $s->loadQuery('mysql://user:password@host/db','SELECT flavor,id FROM
    ice_cream');

    If you pass $options as indexed array, the values in the array appear as choices, and the value attribute of each <option> tag is set to the numeric key of each array element. For example:

    $subjects = array('Math','Ice Fishing','Anatomy');
    $form->addElement('select','subject','Subject(s): ',$subjects);

    When this form is displayed, the select element is expressed with the following HTML:

    <select name="subject">
      <option value="0">Math</option>
      <option value="1">Ice Fishing</option>
      <option value="2">Anatomy</option>
    </select>

    The first element of the $subjects array has the key 0 and the value Math. So the first <option> tag displayed has its value attribute set to 0, and the text between the <option> and </option> tags is Math. If you select Math from the list of choices and submit the form, the value of the submitted form variable subject is 0. If you select Anatomy from the list of choices and submit the form, the value of subject is 1.

    To specify <option> values explicitly, define both keys and values in the $options array:

    $elevator = array(22 => 'Rooftop Dining Room',
      4 => 'Library',
      1 => 'Lobby');
    $form->addElement('select','which_floor','Your Floor: ',$elevator);

    This produces the following HTML:

    <select name="which_floor">
      <option value="22">Rooftop Dining Room</option>
      <option value="4">Library</option>
      <option value="1">Lobby</option>
    </select>

    Note that the order in which the choices appear in the drop-down box is the same as the order in which they are defined in the array. To have string <option> values, use string keys in the array:

    $elevator = array('Rooftop Dining Room' => '22nd Floor',
      'Library' => '4th Floor',
      'Lobby' => '1st Floor');
    $form->addElement('select','which_floor','Your Floor: ',$elevator);

    Just as before, the <option> value attributes are set to the keys of the $elevator array. Because those keys are strings in this example, the value attributes are strings as well:

    <select name="which_floor">

      <option value="Rooftop Dining Room">22nd Floor</option>

      <option value="Library">4th Floor</option>

      <option value="Lobby">1st Floor</option>

    </select>

    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...
     

    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-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway