PHP
  Home arrow PHP arrow Page 4 - Controlling Online Forms with Builder Objects in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
PHP

Controlling Online Forms with Builder Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2006-10-11


    Table of Contents:
  • Controlling Online Forms with Builder Objects in PHP 5
  • Defining a form element class
  • Creating a form builder class
  • Constructing a basic online form

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Controlling Online Forms with Builder Objects in PHP 5 - Constructing a basic online form
    ( Page 4 of 4 )

    Basically, the example that I am just about to provide to you will illustrate the way that the form builder works, based on the class definition that you saw in the previous section. But what's the point of doing this, after all? Well, before I proceed to work directly with directors and builders, I want to demonstrate that all the objects involved in the creation process are fully functional.

    Al right, assuming that all the classes have been placed inside the "classes" directory, a basic contact form might be programmatically built like this:

    // generate sample online form try{ // include class files   require_once('classes/form_element_class.php'); require_once('classes/form_builder_class.php'); // instantiate form builder object $fb=new FormBuilder(); // add some form parts and elements $fb->addFormPart('<table>');   $fb->addFormPart('<tr><td>First Name</td><td>');    $fb->addElement('text',array('name'=>'fname'));    $fb->addFormPart('</tr>');     $fb->addFormPart('<tr><td>Last Name</td><td>');     $fb->addElement('text',array('name'=>'lname'));    $fb->addFormPart('</tr>'); $fb->addFormPart('<tr><td>Email</td><td>'); $fb->addElement('text',array('name'=>'email'));     $fb->addFormPart('</tr>');    $fb->addFormPart('<tr><td>Comments</td><td>');     $fb->addElement('textarea',array('name'=>'comments',
    'rows'=>'10','cols'=>'20'));     $fb->addFormPart('</tr>');     $fb->addFormPart('<tr><td>&nbsp;</td><td>'); $fb->addElement('submit',array('name'=>'send','value'=>
    'Send Data'));    $fb->addFormPart('</tr></table>'); // display online form echo $fb->getForm(); } catch(Exception $e){ echo $e->getMessage(); exit(); }

    In this case, the example listed above shows in a nutshell how the proper combination of only one form builder and some form element objects is good enough to create a sample contact form, which is composed of the following typical input boxes: First Name, Last Name, Email and Comments respectively.

    After running the previous script, it neatly displays the form depicted below:

    As you can see, the above screen shot demonstrates the excellent functionality provided by the form builder class, as well as by the respective form element objects, particularly when used in tandem.

    At this stage, and after proving that the two first components required by the builder pattern work pretty well, the only thing that remains undone is logically creating the respective director class to construct online forms based on its directives.

    However, I saved the best for the last, since this procedure will be covered in the last tutorial. In the meantime, have fun tweaking the code of all the classes shown here!

    To wrap up

    In this second part of the series, I showed you how to use the builder pattern in a more useful fashion: building online forms. Nevertheless, as I said before, the development process is still incomplete, since the corresponding director class hasn't been defined yet.

    That's an excellent reason to catch the last part. See you then!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek