Home arrow PHP arrow Page 3 - Making PHP Forms Object-Oriented
PHP

Making PHP Forms Object-Oriented


In this article Yuri explains an object oriented way to create and use forms on your web site.

Author Info:
By: Yuri Makassiouk
Rating: 4 stars4 stars4 stars4 stars4 stars / 40
January 23, 2003
TABLE OF CONTENTS:
  1. · Making PHP Forms Object-Oriented
  2. · Analysis
  3. · Executing Environment
  4. · Implementing the FormProcessor Class
  5. · Inputs - Brief Introduction
  6. · Example of a Form
  7. · Conclusion

print this article
SEARCH DEVARTICLES

Making PHP Forms Object-Oriented - Executing Environment
(Page 3 of 7 )

Before we go deeper into details, there's one important thing to talk about. That is, how do we organize forms into a branching sequence (I hope, nobody minds me using the word 'wizard' here)?

Here's what I suggest. You may think of it as of some kind of a 'runner' that manipulates instances of classes derived from FormProcessor. This environment knows which form (script in a separate file) should be loaded first. It then includes the script containing a form (FormProcessor's descendant).

This form decides whether it is still displaying itself or just finishing processing of data submitted to it. After storing correct data it reports to the runner: “hey, I'm finished now - look, this is who should be next”.

Based on this information, the runner can load the next form, according to the decision made in the current one. The next form, when included, will sense that it is just loaded for the first time. It will notify the environment (runner) about that and the chain will stall at this point; Of course, waiting for the next form to be submitted.

Before something else distracts us, let's see what I meant here in the code:

<?php

  /**
  * A 'runner' - environment for managing form wizards
  *
  * @author Yuri Makassiouk <racer@bfpg.ru>
  */
  //include('constants.php3');
  //this is the directory where forms (wizard's screens) reside:
  $wizardRoot = '';
  if (!isset($wizardPage))
    //initialize sequence. (This value should normally not be hard-coded)
    $wizardPage = 'reg_form01.php';
  clearstatcache();

  while ($wizardPage) {
    $page = ($wizardRoot . $wizardPage);
    //echo ' ' . $wizardPage . ' ';  // - uncomment this to monitor what's going on
    $wizardPage = ''; // this will stall the wizard
    if (file_exists($page)) {
      // the included file may either set the global variable $wizardPage
      // and that will continue the loop instantly
      // or it may have the pair 'wizardPage=...' get submitted
      // with a form the file contains.
      include($page);  
    }
    else {
      echo "<br><b>Form wizard:</b> cannot find '$page', aborting wizard";
      // this break isn't really necessary - no included file - nobody to
      // set $wizardPage being != ''. But just in case, you know =)
      break;
    }
  }

?>


Now, if you put the code above in a separate file, you may then include that file in your nicely formatted page. This page will be displaying your wizard's screens.
blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials