Graphic Design
  Home arrow Graphic Design arrow Using HTML Quickform for Form Processing
Iron Speed
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  
Download TestComplete 
IBM® developerWorks 
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 / 145
    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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Using HTML Quickform for Form Processing
    (Page 1 of 13 )

    With HTML_QuickForm version 3.1, you can have a consistent look across all your forms and a simplified file upload. This chapter starts with the basics then shows you how to process submitted form data with HTML_QuickForm. (From the book, Essential PHP Tools: Modules, Extensions, and Accelerators, by David Sklar, Apress, 2004, ISBN: 159059280.)

    sklar 

    THE HTML_QUICKFORM module makes working with HTML forms easier. Instead of printing form elements one by one, you use its methods to define a form structure that you can print all at once. HTML_QuickForm automatically preserves defaults across form element submission, displays error messages, assures a consistent look to your forms, and simplifies file uploads.

    This chapter describes HTML_QuickForm version 3.1. First, the chapter covers the basics of using HTML_QuickForm: the different form elements it supports and how to use them together in a form. It also explains element groups, which are a collection of related elements, such as two radio buttons that offer a Yes/No choice or three text boxes that hold the three parts (area code, exchange, and last four digits) of a phone number. Next, the chapter shows you how to process submitted form data with HTML_QuickForm, including how to handle uploaded files. Finally, the chapter details HTML_QuickForm’s validation capabilities. These let you check that the values submitted for specific form elements meet certain requirements, such as exceeding a particular length or matching a specific regular expression. HTML_QuickForm makes it easy to run these validation checks not only on the server once a form has been submitted but via JavaScript in the browser before the fields are submitted.

    Creating and Displaying a Form

    Usually, displaying a form in PHP is a sequence of print statements with logic to handle default values and loops to take care of tedious option lists for giant <select> menus that offer choices among all the days in a month or hours in the day. HTML_QuickForm works differently. The elements in a form are specified, in the order they should appear, and then the entire form is displayed at once. The following section details the basics of using HTML_QuickForm.

    An HTML_QuickForm Example

    This program uses HTML_QuickForm to display, validate, and process a simple form with three elements: a text box, a select box, and a submit button. When the form is submitted, the program checks to make sure that a value was typed in the text box. If so, it prints a message using the submitted data. If not, it redisplays the form with an error message. Figure 3-1 shows the rendered form. Figure 3-2 shows what happens if you submit the form without entering a value in the text box. Figure 3-3 shows what happens when you submit the form with avalue in the text box. The following is a simple example:

    // Load the HTML_QuickForm module
    require 'HTML/QuickForm.php';
    // Instantiate a new form
    $form = new HTML_QuickForm('book');
    // Add a text box
    $form->addElement('text','title','Book Title:');
    // Add a select box
    $subjects = array('Math','Ice Fishing','Anatomy');
    $form->addElement('select','subject','Subject(s): ',$subjects);
    // Add a submit button
    $form->addElement('submit','save','Save Book');
    // Add a validation rule: title is required
    $form->addRule('title','Please Enter a Book Title','required');
    // Call the processing function if the submitted form
    // data is valid; otherwise, display the form
    if ($form->validate()) {
    $form->process('praise_book');
    } else {
    $form->display();
    }
    // Define a function to process the form data
    function praise_book($v) {
    global $subjects;
    // Entity-encode any special characters in $v['title']
    $v['title'] = htmlentities($v['title']);
    print "<i>$v[title]</i> is a great book about ";
    print $subjects[$v['subject']] . '.';
    }

     sklar

    Figure 3-1. HTML_QuickForm produces a form for the browser to display.

     sklar

    Figure 3.2. If you don't enter a title, an error is printed.

     sklar

    Figure 3-3. The praise_book() function prints a message when a title is submitted.

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