#native_company# #native_desc#

Making forms object-oriented Page 3

By Yuri Makasjuk
on October 15, 2001

Executing environment

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 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:



  * A 'runner' - environment for managing form wizards


  * @author Yuri Makassiouk <[email protected]>



  //this is the directory where forms (wizard's screens) reside:

$wizardRoot '';

  if (!isset(

//initialize sequence. (This value should normally not be hard-coded)

$wizardPage 'reg_form01.php';



  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.



    else {

"<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 =)





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