Source for file group.php
Documentation is available at group.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: group.php,v 1.36 2005/07/22 14:19:58 avb Exp $
require_once("HTML/QuickForm/element.php");
* HTML class for a form element group
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* Array of grouped elements
var $_elements = array ();
* String to separate elements
* Required elements in this group
var $_required = array ();
* Whether to change elements' names to $groupName[$elementName] or leave them as is
* @param string $elementName (optional)Group name
* @param array $elementLabel (optional)Group label
* @param array $elements (optional)Group elements
* @param mixed $separator (optional)Use a string for one separator,
* use an array to alternate the separators.
* @param bool $appendName (optional)whether to change elements' names to
* the form $groupName[$elementName] or leave
function HTML_QuickForm_group($elementName=null , $elementLabel=null , $elements=null , $separator=null , $appendName = true )
$this->HTML_QuickForm_element ($elementName, $elementLabel);
if (isset ($elements) && is_array($elements)) {
$this->_separator = $separator;
if (isset ($appendName)) {
$this->_appendName = $appendName;
* @param string $name Group name
* Sets values for group's elements
* @param mixed Values for group's elements
$this->_createElementsIfNotExist ();
if (!$this->_appendName) {
$v = $this->_elements[$key]->_findValue ($value);
$this->_elements[$key]->onQuickFormEvent ('setGroupValue', $v, $this);
$elementName = $this->_elements[$key]->getName ();
$index = strlen($elementName) ? $elementName : $key;
if (isset ($value[$index])) {
$this->_elements[$key]->onQuickFormEvent ('setGroupValue', $value[$index], $this);
} elseif (isset ($value)) {
$this->_elements[$key]->onQuickFormEvent ('setGroupValue', $value, $this);
* Returns the value of the group
$element = & $this->_elements[$key];
switch ($element->getType ()) {
$v = $element->getChecked ()? $element->getValue (): null;
$v = $element->getChecked ()? true: null;
$v = $element->getValue ();
$elementName = $element->getName ();
$value = is_null($value)? array (): array ($value);
if ('' === $elementName) {
$value[$elementName] = $v;
* Sets the grouped elements
* @param array $elements Array of elements
if ($this->_flagFrozen) {
} // end func setElements
* Gets the grouped elements
$this->_createElementsIfNotExist ();
} // end func getElements
* Gets the group type based on its elements
* Will return 'mixed' if elements contained in the group
* are of different types.
* @return string group elements type
$this->_createElementsIfNotExist ();
$type = $this->_elements[$key]->getType ();
if ($type != $prevType && $prevType != '') {
} // end func getGroupType
* Returns Html for the group
include_once('HTML/QuickForm/Renderer/Default.php');
$renderer->setElementTemplate ('{element}');
return $renderer->toHtml ();
* Returns the element name inside the group such as found in the html form
* @param mixed $index Element name or element index in the group
* @return mixed string with element name, false if not found
$this->_createElementsIfNotExist ();
if (is_int($index) && isset ($this->_elements[$index])) {
$elementName = $this->_elements[$index]->getName ();
if (isset ($elementName) && $elementName == '') {
if ($this->_appendName) {
$elementName = $this->getName(). '['. $elementName. ']';
$elementName = $this->_elements[$key]->getName ();
if ($index == $elementName) {
if ($this->_appendName) {
$elementName = $this->getName(). '['. $elementName. ']';
} elseif ($this->_appendName && $this->getName(). '['. $elementName. ']' == $index) {
} //end func getElementName
* Returns the value of field without HTML tags
$this->_createElementsIfNotExist ();
if (false === ($flags[$key] = $this->_elements[$key]->isFrozen ())) {
$this->_elements[$key]->freeze ();
$this->_elements[$key]->unfreeze ();
} //end func getFrozenHtml
// {{{ 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->_createElementsIfNotExist ();
if ($this->_appendName) {
$elementName = $this->_elements[$key]->getName ();
$this->_elements[$key]->setName ($this->getName());
} elseif ('' === $elementName) {
$this->_elements[$key]->setName ($this->getName() . '[' . $key . ']');
$this->_elements[$key]->setName ($this->getName() . '[' . $elementName . ']');
$this->_elements[$key]->onQuickFormEvent ('updateValue', $arg, $caller);
if ($this->_appendName) {
$this->_elements[$key]->setName ($elementName);
parent ::onQuickFormEvent ($event, $arg, $caller);
} // end func onQuickFormEvent
* @param object An HTML_QuickForm_Renderer object
* @param bool Whether a group is required
* @param string An error message associated with a group
function accept(&$renderer, $required = false , $error = null )
$this->_createElementsIfNotExist ();
$renderer->startGroup ($this, $required, $error);
$element = & $this->_elements[$key];
if ($this->_appendName) {
$elementName = $element->getName ();
if (isset ($elementName)) {
$element->setName ($name . '['. (strlen($elementName)? $elementName: $key) . ']');
$element->setName ($name);
$required = !$element->isFrozen () && in_array($element->getName (), $this->_required);
$element->accept ($renderer, $required);
// restore the element's name
if ($this->_appendName) {
$element->setName ($elementName);
$renderer->finishGroup ($this);
* As usual, to get the group's value we access its elements and call
* their exportValue() methods
$elementName = $this->_elements[$key]->getName ();
if ($this->_appendName) {
$this->_elements[$key]->setName ($this->getName());
} elseif ('' === $elementName) {
$this->_elements[$key]->setName ($this->getName() . '[' . $key . ']');
$this->_elements[$key]->setName ($this->getName() . '[' . $elementName . ']');
$v = $this->_elements[$key]->exportValue ($submitValues, $assoc);
if ($this->_appendName) {
$this->_elements[$key]->setName ($elementName);
// Make $value an array, we will use it like one
// just like HTML_QuickForm::exportValues()
// just like getValue(), but should work OK every time here
} elseif ('' === $elementName) {
$value[$elementName] = $v;
// do not pass the value through _prepareValue, we took care of this already
* Creates the group's elements.
* This should be overriden by child classes that need to create their
* elements. The method will be called automatically when needed, calling
* it from the constructor is discouraged as the constructor is usually
* called _twice_ on element creation, first time with _no_ parameters.
function _createElements ()
// {{{ _createElementsIfNotExist()
* A wrapper around _createElements()
* This method calls _createElements() if the group's _elements array
* is empty. It also performs some updates, e.g. freezes the created
* elements if the group is already frozen.
function _createElementsIfNotExist ()
if (empty ($this->_elements)) {
$this->_createElements ();
if ($this->_flagFrozen) {
$this->_elements[$key]->freeze ();
$this->_elements[$key]->unfreeze ();
// {{{ setPersistantFreeze()
parent ::setPersistantFreeze ($persistant);
$this->_elements[$key]->setPersistantFreeze ($persistant);
} //end class HTML_QuickForm_group
Documentation generated on Mon, 11 Mar 2019 14:16:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|