Design Usability
  Home arrow Design Usability arrow Page 6 - 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  
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? 
DESIGN USABILITY

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

    Table of Contents:
  • Using HTML_QuickForm To Manage Web Forms, Part 1
  • Installing The HTML_QuickForm Package
  • My First HTML_QuickForm
  • FORM Elements
  • Adding Standard HMTL FORM Elements
  • Defining FORM Controls, Submitting Data
  • Grouping
  • "Checkbox" and "Radio" Elements
  • Drop Down Control and Hidden Element
  • Implementing Form Validations
  • Password Field Validation
  • Processing Data With HTML_QuickForm
  • 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 1 - Defining FORM Controls, Submitting Data


    (Page 6 of 13 )

    Next, we have the definition of the "checkbox", "submit" and "reset" <FORM> controls.

    <?php

    // snip

    $obj_registration_form->addElement('checkbox', 'txtNewsletter', 'Subscribe to Newsletter:', 'Yes');

    $obj_registration_form->addElement('html', '<tr><td colspan="2">&nbsp;</td></tr>');

    $obj_registration_form->addElement('submit', 'btnSubmit', 'Register');
    $obj_registration_form->addElement('reset', 'btnReset', 'Start Again');

    // snip

    ?>

    Once again, I have invoked the resourceful addElement() method with the appropriate keywords - "checkbox", "submit" and "reset" - to add the required elements.

    Next, I have to handle the submission of the Web form data itself. Since I have not specified any value for the "action" attribute of the <FORM> element, the page will post the data to itself when I click the "Register" submit button. Take a look at the next code snippet.

    <?php

    // snip

    // filters before validation comes here

    // validation rules come here

    // validate form
    if($obj_registration_form->validate()) {

      // filters after validation comes here

      // if data is valid, process form details
      echo '<pre>';
      var_dump($obj_registration_form->exportValues());
      echo '</pre>';

      // free the form values
      $obj_registration_form->freeze(); 
    }

    // snip

    ?>

    I have invoked the validate() method to verify the data entered by the user. Since I have not implemented any validation (more on this later), the form submission goes through without any hitch. Take a look at the output that you should see in your browser:

    Using HTML_QuickForm

    The above output display the values stored in the array returned by the exportValues() method. Next, I have called the freeze() method - this is used to "freeze" the Web form data, i.e. a user cannot modify the data once it has been frozen, as is evident from the output listed above.

    <?php
         
      // snip

      // display the form
      $obj_registration_form->display();

      // snip

    ?>

    The final act - I have called the display() method in order to render the Web form in the browser. If the Web form has been "frozen," this method will render the values submitted by the user, without the actual HTML <FORM> elements.

    What I finally have is a fully functional Web form without typing a single line of HTML code in my PHP script!

    More Design Usability Articles
    More By Harish Kamath


       · When first time i saw this article i thought that it will solve all my problems that...
       · Then install the pear common package.
       · Great article! Where and how does the $ary_artist_info array get created in this...
     

    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-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek