1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Alexey Borzov <[email protected]> |
// | Bertrand Mansion <[email protected]> |
// +----------------------------------------------------------------------+
//
// $Id: Page.php,v 1.3 2004/03/02 21:15:52 avb Exp $
require_once 'HTML/QuickForm.php';
/**
* The class represents a page of a multipage form.
*
* Generally you'll need to subclass this and define your buildForm()
* method that will build the form. While it is also possible to instantiate
* this class and build the form manually, this is not the recommended way.
*
* @author Alexey Borzov <[email protected]>
* @package HTML_QuickForm_Controller
* @version $Revision: 1.3 $
*/
class HTML_QuickForm_Page extends HTML_QuickForm
{
/**
* Contains the mapping of actions to corresponding HTML_QuickForm_Action objects
* @var array
*/
var $_actions = array();
/**
* Contains a reference to a Controller object containing this page
* @var object HTML_QuickForm_Controller
* @access public
*/
var $controller = null;
/**
* Should be set to true on first call to buildForm()
* @var bool
*/
var $_formBuilt = false;
/**
* Class constructor
*
* @access public
*/
function HTML_QuickForm_Page($formName, $method = 'post', $target = '_self', $attributes = null)
{
$this->HTML_QuickForm($formName, $method, '', $target, $attributes);
}
/**
* Registers a handler for a specific action.
*
* @access public
* @param string name of the action
* @param object HTML_QuickForm_Action the handler for the action
*/
function addAction($actionName, &$action)
{
$this->_actions[$actionName] =& $action;
}
/**
* Handles an action.
*
* If an Action object was not registered here, controller's handle()
* method will be called.
*
* @access public
* @param string Name of the action
*/
function handle($actionName)
{
if (isset($this->_actions[$actionName])) {
return $this->_actions[$actionName]->perform($this, $actionName);
} else {
return $this->controller->handle($this, $actionName);
}
}
/**
* Returns a name for a submit button that will invoke a specific action.
*
* @access public
* @param string Name of the action
* @return string "name" attribute for a submit button
*/
function getButtonName($actionName)
{
return '_qf_' . $this->getAttribute('id') . '_' . $actionName;
}
/**
* Loads the submit values from the array.
*
* The method is NOT intended for general usage.
*
* @param array 'submit' values
* @access public
*/
function loadValues($values)
{
$this->_submitValues = $values;
foreach (array_keys($this->_elements) as $key) {
$this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
}
}
/**
* Builds a form.
*
* You should override this method when you subclass HTML_QuickForm_Page,
* it should contain all the necessary addElement(), applyFilter(), addRule()
* and possibly setDefaults() and setConstants() calls. The method will be
* called on demand, so please be sure to set $_formBuilt property to true to
* assure that the method works only once.
*
* @access public
* @abstract
*/
function buildForm()
{
$this->_formBuilt = true;
}
/**
* Checks whether the form was already built.
*
* @access public
* @return bool
*/
function isFormBuilt()
{
return $this->_formBuilt;
}
/**
* Sets the default action invoked on page-form submit
*
* This is necessary as the user may just press Enter instead of
* clicking one of the named submit buttons and then no action name will
* be passed to the script.
*
* @access public
* @param string default action name
*/
function setDefaultAction($actionName)
{
if ($this->elementExists('_qf_default')) {
$element =& $this->getElement('_qf_default');
$element->setValue($this->getAttribute('id') . ':' . $actionName);
} else {
$this->addElement('hidden', '_qf_default', $this->getAttribute('id') . ':' . $actionName);
}
}
}
?>
|