Source for file element.php
Documentation is available at element.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 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 |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
// | Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
// $Id: element.php,v 1.33 2005/06/24 17:58:29 avb Exp $
require_once('HTML/Common.php');
* Base class for form elements
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* Flag to tell if element is frozen
var $_flagFrozen = false;
* Does the element support persistant data when frozen
var $_persistantFreeze = false;
* @param string Name of the element
* @param mixed Label(s) for the element
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
HTML_Common ::HTML_Common ($attributes);
if (isset ($elementName)) {
if (isset ($elementLabel)) {
* Returns the current API version
* Sets the input field name
* @param string $name Input field name attribute
* Returns the element name
* Sets the value of the form element
* @param string $value Default value of the form element
* Returns the value of the form element
* Freeze the element so that only its value is returned
$this->_flagFrozen = true;
* Unfreezes the element so that it becomes editable
$this->_flagFrozen = false;
* Returns the value of field without HTML tags
$this->_getPersistantData ();
} //end func getFrozenHtml
// {{{ _getPersistantData()
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
function _getPersistantData ()
if (!$this->_persistantFreeze) {
$id = $this->getAttribute ('id');
return '<input' . $this->_getAttrString (array (
) + (isset ($id)? array ('id' => $id): array ())) . ' />';
* Returns whether or not the element is frozen
return $this->_flagFrozen;
// {{{ setPersistantFreeze()
* Sets wether an element value should be kept in an hidden field
* when the element is frozen or not
* @param bool $persistant True if persistant value
$this->_persistantFreeze = $persistant;
} //end func setPersistantFreeze
* Sets display text for the element
* @param string $label Display text for the element
* Returns display text for the element
* Tries to find the element value from the values array
function _findValue (&$values)
if (isset ($values[$elementName])) {
return $values[$elementName];
} elseif (strpos($elementName, '[')) {
$myVar = "['" . str_replace(array (']', '['), array ('', "']['"), $elementName) . "']";
return eval (" return (isset(\$values$myVar)) ? \$values$myVar : null;" );
// {{{ onQuickFormEvent()
* Called by HTML_QuickForm whenever form event is made on this element
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object $caller calling object
$this->$className($arg[0 ], $arg[1 ], $arg[2 ], $arg[3 ], $arg[4 ]);
// constant values override both default and submitted ones
// default values are overriden by submitted
$value = $this->_findValue ($caller->_constantValues );
$value = $this->_findValue ($caller->_submitValues );
$value = $this->_findValue ($caller->_defaultValues );
} // end func onQuickFormEvent
* @param object An HTML_QuickForm_Renderer object
* @param bool Whether an element is required
* @param string An error message associated with an element
function accept(&$renderer, $required=false , $error=null )
$renderer->renderElement ($this, $required, $error);
* Automatically generates and assigns an 'id' attribute for the element.
* Currently used to ensure that labels work on radio buttons and
* checkboxes. Per idea of Alexander Radivanovich.
if (!$this->getAttribute ('id')) {
$this->updateAttributes (array ('id' => 'qf_' . substr (md5 (microtime () . $idx++ ), 0 , 6 )));
} // end func _generateId
* Returns a 'safe' element's value
* @param array array of submitted values to search
* @param bool whether to return the value as associative array
$value = $this->_findValue ($submitValues);
return $this->_prepareValue ($value, $assoc);
* Used by exportValue() to prepare the value for returning
* @param mixed the value found in exportValue()
* @param bool whether to return the value as associative array
function _prepareValue ($value, $assoc)
return array ($name => $value);
$myIndex = "['" . str_replace(array (']', '['), array ('', "']['"), $name) . "']";
eval (" \$valueAry$myIndex = \$value;" );
} // end class HTML_QuickForm_element
Documentation generated on Mon, 11 Mar 2019 14:16:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|