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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
<?php
/*
File: form.inc.php
HTML Control Library - Form Level Tags
Title: xajax HTML control class library
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
/*
@package xajax
@version $Id: form.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
@copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
@copyright Copyright (c) 2008-2009 by Joseph Woolley, Steffen Konerow, Jared White & J. Max Wilson
@license http://www.xajaxproject.org/bsd_license.txt BSD License
*/
/*
Section: Description
This file contains the class declarations for the following HTML Controls:
- form
- input, textarea, select, optgroup, option
- label
- fieldset, legend
The following tags are deprecated as of HTML 4.01, therefore, they will not
be supported:
- isindex
*/
class clsForm extends xajaxControlContainer
{
function clsForm($aConfiguration=array())
{
if (false == isset($aConfiguration['attributes']))
$aConfiguration['attributes'] = array();
if (false == isset($aConfiguration['attributes']['method']))
$aConfiguration['attributes']['method'] = 'POST';
if (false == isset($aConfiguration['attributes']['action']))
$aConfiguration['attributes']['action'] = '#';
xajaxControlContainer::xajaxControlContainer('form', $aConfiguration);
}
}
class clsInput extends xajaxControl
{
function clsInput($aConfiguration=array())
{
xajaxControl::xajaxControl('input', $aConfiguration);
}
}
class clsInputWithLabel extends clsInput
{
var $objLabel;
var $sWhere;
var $objBreak;
function clsInputWithLabel($sLabel, $sWhere, $aConfiguration=array())
{
clsInput::clsInput($aConfiguration);
$this->objLabel =& new clsLabel(array(
'child' => new clsLiteral($sLabel)
));
$this->objLabel->setControl($this);
$this->sWhere = $sWhere;
$this->objBreak =& new clsBr();
}
function printHTML($sIndent='')
{
if ('left' == $this->sWhere || 'above' == $this->sWhere)
$this->objLabel->printHTML($sIndent);
if ('above' == $this->sWhere)
$this->objBreak->printHTML($sIndent);
clsInput::printHTML($sIndent);
if ('below' == $this->sWhere)
$this->objBreak->printHTML($sIndent);
if ('right' == $this->sWhere || 'below' == $this->sWhere)
$this->objLabel->printHTML($sIndent);
}
}
/*
Class: clsSelect
A <xajaxControlContainer> derived class that assists in the construction
of an HTML select control.
This control can only accept <clsOption> controls as children.
*/
class clsSelect extends xajaxControlContainer
{
/*
Function: clsSelect
Construct and initialize an instance of the class. See <xajaxControlContainer>
for details regarding the aConfiguration parameter.
*/
function clsSelect($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('select', $aConfiguration);
}
/*
Function: addOption
Used to add a single option to the options list.
sValue - (string): The value that is returned as the form value
when this option is the selected option.
sText - (string): The text that is displayed in the select box when
this option is the selected option.
*/
function addOption($sValue, $sText)
{
$optionNew =& new clsOption();
$optionNew->setValue($sValue);
$optionNew->setText($sText);
$this->addChild($optionNew);
}
/*
Function: addOptions
Used to add a list of options.
aOptions - (associative array): A list of key/value pairs that will
be passed to <clsSelect->addOption>.
*/
function addOptions($aOptions, $aFields=array())
{
if (0 == count($aFields))
foreach ($aOptions as $sValue => $sText)
$this->addOption($sValue, $sText);
else if (1 < count($aFields))
foreach ($aOptions as $aOption)
$this->addOption($aOption[$aFields[0]], $aOption[$aFields[1]]);
else
trigger_error('Invalid list of fields passed to clsSelect::addOptions; should be array of two strings.'
. $this->backtrace(),
E_USER_ERROR
);
}
}
/*
Class: clsOptionGroup
A <xajaxControlContainer> derived class that can be used around a list of <clsOption>
objects to help the user find items in a select list.
*/
class clsOptionGroup extends xajaxControlContainer
{
function clsOptionGroup($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('optgroup', $aConfiguration);
}
/*
Function: addOption
Used to add a single option to the options list.
sValue - (string): The value that is returned as the form value
when this option is the selected option.
sText - (string): The text that is displayed in the select box when
this option is the selected option.
*/
function addOption($sValue, $sText)
{
$optionNew =& new clsOption();
$optionNew->setValue($sValue);
$optionNew->setText($sText);
$this->addChild($optionNew);
}
/*
Function: addOptions
Used to add a list of options.
aOptions - (associative array): A list of key/value pairs that will
be passed to <clsSelect->addOption>.
*/
function addOptions($aOptions, $aFields=array())
{
if (0 == count($aFields))
foreach ($aOptions as $sValue => $sText)
$this->addOption($sValue, $sText);
else if (1 < count($aFields))
foreach ($aOptions as $aOption)
$this->addOption($aOption[$aFields[0]], $aOption[$aFields[1]]);
else
trigger_error('Invalid list of fields passed to clsOptionGroup::addOptions; should be array of two strings.'
. $this->backtrace(),
E_USER_ERROR
);
}
}
/*
Class: clsOption
A <xajaxControlContainer> derived class that assists with the construction
of HTML option tags that will be assigned to an HTML select tag.
This control can only accept <clsLiteral> objects as children.
*/
class clsOption extends xajaxControlContainer
{
/*
Function: clsOption
Constructs and initializes an instance of this class. See <xajaxControlContainer>
for more information regarding the aConfiguration parameter.
*/
function clsOption($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('option', $aConfiguration);
}
/*
Function: setValue
Used to set the value associated with this option. The value is sent as the
value of the select control when this is the selected option.
*/
function setValue($sValue)
{
$this->setAttribute('value', $sValue);
}
/*
Function: setText
Sets the text to be shown in the select control when this is the
selected option.
*/
function setText($sText)
{
$this->clearChildren();
$this->addChild(new clsLiteral($sText));
}
}
class clsTextArea extends xajaxControlContainer
{
function clsTextArea($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('textarea', $aConfiguration);
$this->sClass = '%block';
}
}
class clsLabel extends xajaxControlContainer
{
var $objFor;
function clsLabel($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('label', $aConfiguration);
}
function setControl(&$objControl)
{
if (false == is_a($objControl, 'xajaxControl'))
trigger_error(
'Invalid control passed to clsLabel::setControl(); should be xajaxControl.'
. $this->backtrace(),
E_USER_ERROR);
$this->objFor =& $objControl;
}
function printHTML($sIndent='')
{
$this->aAttributes['for'] = $this->objFor->aAttributes['id'];
xajaxControlContainer::printHTML($sIndent);
}
}
class clsFieldset extends xajaxControlContainer
{
function clsFieldset($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('fieldset', $aConfiguration);
$this->sClass = '%block';
}
}
class clsLegend extends xajaxControlContainer
{
function clsLegend($aConfiguration=array())
{
xajaxControlContainer::xajaxControlContainer('legend', $aConfiguration);
$this->sClass = '%inline';
}
}
|