Graphic Design
  Home arrow Graphic Design arrow Page 3 - 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 - Individual Elements


    (Page 3 of 13 )

    There are two ways to add elements to a form. The first is to use the addElement() method of the form object. This is how you built the form in the previous section. Because you can pass addElement() arguments that control various aspects and attributes of the form element, it’s a flexible one-step way to populate your form. The other way to add elements to a form is to create elements as separate objects with the createElement() static method. This method takes the same arguments as addElement() but returns an object. You can then add the element to the form by passing the object to addElement(). In this example, two text elements are added to the form: the first using just addElement() and the second using createElement() with addElement().

    // $form is an HTML_QuickForm object
    // add the text field in one step with addElement()
    $form->addElement('text','first_name','First Name:');
    // create the element with createElement() and then pass it to addElement()
    $element =& HTML_QuickForm::createElement('text','last_name','Last Name:');
    $form->addElement($element);

    To avoid making copies of the object as it is created, it is necessary to retrieve the result of createElement() by reference with the & operator. This is not necessary in PHP 5. Using createElement() adds an extra step, but it also gives you access to the element object. You can call methods on the element object to alter its behavior. For example, the text element has methods called setSize() and setMaxlength(), which set the size and maxlength attributes of the element, respectively:

    $element =& HTML_QuickForm::createElement('text','last_name','Last Name:');
    $element->setSize(10); // Render the element as ten characters wide $element->setMaxlength(30); // Allow no more than 30 characters of input
    $form->addElement($element);

    If you add elements to the form without using createElement(), you can retrieve element objects later with getElement(). Pass it the name of an element, and it returns the corresponding element object. You must retrieve the object by reference so that any changes you make to it are accurately reflected in the form:

    $form->addElement('text','first_name','First Name:');
    $element=& $form->getElement('first_name');
    $element->setSize(40);

    Some element methods retrieve information about the element instead of modifying it. For example, getName() returns an element’s name:

    $form->addElement('text','first_name','First Name:');
    $element=& $form->getElement('first_name');
    // this sets $name to "first_name"
    $name = $element->getName();

    All elements have the methods setName(), getName(), setValue(), getValue(), setLabel(), and getLabel().

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek