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

Controlling Online Forms with Builder Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      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


    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!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Over this final article of this series, the builder pattern is applied, in order to...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT