HTML_QuickForm, Confirmation and Review Page
| From: | Trevan Devaun Richins | Date: | Fri, 02 Jul 2004 23:05:42 +0000 |
| Subject: | HTML_QuickForm, Confirmation and Review Page | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-13470@lists.php.net to get a copy of this message | ||
I am trying to create a simple confirm page for my form where it will display the values submitted for a final review, but I seem to be coming across a bit of a problem. Instead of printing out the submitted values, it is printing out the default values. Here is an example of what I am trying to do.
<?php
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', 'name', 'Enter your name:', array('size' => 50, 'maxlength' => 255));
// Note how we set the name of the submit button
$this->addElement('submit', $this->getButtonName('submit'), 'Send');
// Define filters and validation rules
$this->applyFilter('name', 'trim'); $this->addRule('name', 'Please enter your name', 'required', null, 'client'); $this->setDefaultAction('submit'); } }
class SecondPage extends HTML_QuickForm_Page
{
function buildForm() {
$this->_formBuilt = true;
$this->addElement('text','name','Make Sure Your Name is Spelled Correctly:',null);
$this->freeze('name');
}
}
// Action to process the form
class ActionProcess extends HTML_QuickForm_Action
{ function perform(&$page, $actionName) {
echo '<h1>Hello, ' . htmlspecialchars($page->exportValue('name')) . '!</h1>';
} } $page1 =& new FirstPage('firstForm');
$page2 =& new SecondPage('secondForm');
// We only add the 'process' handler, Controller will care for default ones
$page1->addAction('process', new ActionProcess()); // 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($page1);
$controller->addPage($page2);
// Process the request
$controller->run();
?>
If you notice, it is the example from the manual. I think my problem is the name being the same, and that I might need to change the name and then set the value for the new frozen text field. Anybody have an idea or suggestion on how I can create this review page?
Trevan