I have a few sites which contain forms that span multiple screens (all
contained in two scripts though...)
theforms.php
<?
// Include file
class theForms
{
function showScreen1()
{
global $error;
?>
The html for the form.
<? if($error){ echo $error; } ?>
<?
}//function showScreen1
function saveScreen1()
{
global $HTTP_POST_VARS;
// save the input into a database or file etc.
if(success)
{
return true;
}
else
{
return false;
}
}//function saveScreen1
function showScreen2()
{
global $error;
?>
The html for the form.
<? if($error){ echo $error; } ?>
<?
}//function showScreen1
function saveScreen2()
{
global $HTTP_POST_VARS;
// save the input into a database or file etc.
if(success)
{
return true;
}
else
{
return false;
}
}//function saveScreen1
}
?>
forms.php
<?
include('theforms.php');
$theForms = new theForms;
if(!isset($screen)){ $screen = 'showScreen1'; }
switch($screen)
{
case 'showScreen1':
$theForms->showScreen1();
break;
case 'saveScreen1':
if($theForms->saveScreen1() != true)
{
$error = "it died!";
$theForms->showScreen1();
break;
}
case 'showScreen2':
$theForms->showScreen2();
break;
}//Switch
?>
so basically I put all the html into functions in a class, and control the
flow of the form with the switch statement, that way if my function that
saves the data comes across an error, it get's trapped and shows that screen
again...
Has anybody else found a more elegant way to accomplish this? It works quite
nice, but I was wondering how other people go about creating their forms.
Thanks,
-Jonathan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]