2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5 * Class representing a page of a multipage form.
9 * LICENSE: This source file is subject to version 3.01 of the PHP license
10 * that is available through the world-wide-web at the following URI:
11 * http://www.php.net/license/3_01.txt If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
16 * @package HTML_QuickForm_Controller
17 * @author Alexey Borzov <avb@php.net>
18 * @author Bertrand Mansion <bmansion@mamasam.com>
19 * @copyright 2003-2007 The PHP Group
20 * @license http://www.php.net/license/3_01.txt PHP License 3.01
21 * @version CVS: $Id: Page.php,v 1.7 2007/05/18 09:34:18 avb Exp $
22 * @link http://pear.php.net/package/HTML_QuickForm_Controller
26 * Create, validate and process HTML forms
28 require_once 'HTML/QuickForm.php';
31 * Class representing a page of a multipage form.
33 * Generally you'll need to subclass this and define your buildForm()
34 * method that will build the form. While it is also possible to instantiate
35 * this class and build the form manually, this is not the recommended way.
38 * @package HTML_QuickForm_Controller
39 * @author Alexey Borzov <avb@php.net>
40 * @author Bertrand Mansion <bmansion@mamasam.com>
41 * @version Release: 1.0.9
43 class HTML_QuickForm_Page
extends HTML_QuickForm
46 * Contains the mapping of actions to corresponding HTML_QuickForm_Action objects
49 var $_actions = array();
52 * Contains a reference to a Controller object containing this page
53 * @var HTML_QuickForm_Controller
56 var $controller = null;
59 * Should be set to true on first call to buildForm()
62 var $_formBuilt = false;
69 function HTML_QuickForm_Page($formName, $method = 'post', $target = '', $attributes = null)
71 $this->HTML_QuickForm($formName, $method, '', $target, $attributes);
76 * Registers a handler for a specific action.
79 * @param string name of the action
80 * @param HTML_QuickForm_Action the handler for the action
82 function addAction($actionName, &$action)
84 $this->_actions
[$actionName] =& $action;
91 * If an Action object was not registered here, controller's handle()
92 * method will be called.
95 * @param string Name of the action
98 function handle($actionName)
100 if (isset($this->_actions
[$actionName])) {
101 return $this->_actions
[$actionName]->perform($this, $actionName);
103 return $this->controller
->handle($this, $actionName);
109 * Returns a name for a submit button that will invoke a specific action.
112 * @param string Name of the action
113 * @return string "name" attribute for a submit button
115 function getButtonName($actionName, $subActionName = null)
117 if ( $subActionName != null ) {
118 return '_qf_' . $this->getAttribute('id') . '_' . $actionName . '_' . $subActionName;
120 return '_qf_' . $this->getAttribute('id') . '_' . $actionName;
126 * Loads the submit values from the array.
128 * The method is NOT intended for general usage.
130 * @param array 'submit' values
133 function loadValues($values)
135 $this->_flagSubmitted
= true;
136 $this->_submitValues
= $values;
137 foreach (array_keys($this->_elements
) as $key) {
138 $this->_elements
[$key]->onQuickFormEvent('updateValue', null, $this);
146 * You should override this method when you subclass HTML_QuickForm_Page,
147 * it should contain all the necessary addElement(), applyFilter(), addRule()
148 * and possibly setDefaults() and setConstants() calls. The method will be
149 * called on demand, so please be sure to set $_formBuilt property to true to
150 * assure that the method works only once.
157 $this->_formBuilt
= true;
162 * Checks whether the form was already built.
167 function isFormBuilt()
169 return $this->_formBuilt
;
174 * Sets the default action invoked on page-form submit
176 * This is necessary as the user may just press Enter instead of
177 * clicking one of the named submit buttons and then no action name will
178 * be passed to the script.
181 * @param string default action name
183 function setDefaultAction($actionName)
185 if ($this->elementExists('_qf_default')) {
186 $element =& $this->getElement('_qf_default');
187 $element->setValue($this->getAttribute('id') . ':' . $actionName);
189 $this->addElement('hidden', '_qf_default', $this->getAttribute('id') . ':' . $actionName);
195 * Returns 'safe' elements' values
197 * @param mixed Array/string of element names, whose values we want. If not set then return all elements.
198 * @param bool Whether to remove internal (_qf_...) values from the resultant array
200 function exportValues($elementList = null, $filterInternal = false)
202 $values = parent
::exportValues($elementList);
203 if ($filterInternal) {
204 foreach (array_keys($values) as $key) {
205 if (0 === strpos($key, '_qf_')) {
206 unset($values[$key]);