PEAR::HTML_QuickForm_Controller question
| From: | Evan Wagner | Date: | Tue, 04 May 2004 16:27:48 +0000 |
| Subject: | PEAR::HTML_QuickForm_Controller question | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-12302@lists.php.net to get a copy of this message | ||
Hello everyone,
I have a question about what I am doing wrong. I will paste my code
below. I want the pages to go from 1-3 and I either get the last page or
the first two pages. It's strange. Anyways, I hope someone knows QFC.
//Begin code
// Load the controller
require_once 'HTML/QuickForm/Controller.php';
// Load the base Action class (we will subclass it later)
require_once 'HTML/QuickForm/Action.php';
// Class representing a form
class FirstPage extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt = true;
// Add some elements to the form
$this->addElement('header', null, 'QuickForm tutorial example');
$this->addElement('text', 'fname', 'Enter your first
name:',
array('size' => 50, 'maxlength' => 255));
// Note how we set the name of the submit button
$this->addElement('submit', $this->getButtonName('next'),
'Send');
$this->setDefaultAction('next');
}
}
class SecondPage extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt = true;
// Add some elements to the form
$this->addElement('header', null, 'QuickForm tutorial example');
$this->addElement('text', 'mname', 'Enter your middle
name:',
array('size' => 50, 'maxlength' => 255));
// Note how we set the name of the submit button
$this->addElement('submit', $this->getButtonName('next'),
'Send');
$this->setDefaultAction('next');
}
}
class ThirdPage extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt = true;
// Add some elements to the form
$this->addElement('header', null, 'QuickForm tutorial example');
$this->addElement('text', 'lname', 'Enter your last name:',
array('size' => 50, 'maxlength' => 255));
// Note how we set the name of the submit button
$this->addElement('submit', $this->getButtonName('submit'),
'Send');
$this->setDefaultAction('submit');
}
}
// Action to process the form
class ActionProcess extends HTML_QuickForm_Action
{
function perform(&$page, $actionName)
{
}
}
class ActionProcess2 extends HTML_QuickForm_Action
{
function perform(&$page2, $actionName)
{
echo '<h1>Hello, ' .
htmlspecialchars($page2->exportValue('lname')) . '!</h1>';
}
}
class ActionProcess3 extends HTML_QuickForm_Action
{
function perform(&$page3, $actionName)
{
echo '<h1>Hello, ' .
htmlspecialchars($page3->exportValue('lname')) . '!</h1>';
}
}
$page =& new FirstPage('firstForm');
$page2 =& new SecondPage('firstForm');
$page3 =& new ThirdPage('firstForm');
// We only add the 'process' handler, Controller will care for default
ones
$page->addAction('process', new ActionProcess());
$page->addAction('next', new ActionProcess2());
$page->addAction('display', new ActionProcess3());
// Instantiate the Controller
$controller =& new HTML_QuickForm_Controller('tutorial');
// Set defaults for the form elements
$controller->setDefaults(array(
'name' => 'Joe User'
));
// Add the page to Controller
$controller->addPage($page);
$controller->addPage($page2);
$controller->addPage($page3);
// Process the request
$controller->run();
//End Code
Thanks,
Evan Wagner
evanw@uca.edu