/** * Associative array of attributes for each of the individual form elements. * NOTE: use "_qf_other" for the other radio button, and "_qf_other_text" * for the text field. * * @var array Associative array of attributes (see HTML_Common) * @access private */var $_individualAttributes;

// }}} // {{{ HTML_QuickForm_altselect

/** * Constructor. Used to distinguish the attributes array which should be * an associative array of options to either a typical HTML attribute string * or another associative array * * @param string $elementName select name attribute * @param mixed $elementLabel label(s) for the select * @param mixed $options data to be used to populate options * @param mixed $attributes an associative array of option value * -> attributes. Each attribute is either * a typical HTML attribute string or an * associative array. * NOTE: use "_qf_other" for the other radio * button, and "_qf_other_text" for the * text field. * @return void */function HTML_QuickForm_altselect($elementName = null,$elementLabel = null,$options = null,$attributes = null) { if (func_get_args()) {HTML_QuickForm_select::HTML_QuickForm_select($elementName,$elementLabel,$options);$this->_individualAttributes = $attributes; } }

/** * Arrange the buttons/boxes and other bits either concatenated as a html * string or in an array. When this element is registered as a group, * getElements should act in the same way as HTML_QuickForm_group::getElements(). * (Therefore the default must be to format as an array) * * @param bool $formatArray set true for an array (default), false for HTML * @access public * @see HTML_QuickForm_group::getElements() * @return mixed Array or HTML string */function getElements($formatArray = true) {$html_func_to_use = $this->_flagFrozen ? 'getFrozenHtml' : 'toHtml';$is_multiple = $this->getMultiple();

// if either the other button is selected, or some text is entered // (meaning _qf_other will also be a value), then set the value of // the other value in the text field.if (is_array($this->_values) &&in_array('_qf_other', $this->_values) && isset($this->_otherValue)) {$element->updateAttributes(array('value' => $this->_otherValue)); }// otherwise just disable it // only disable with javascript otherwise if the browser doesn't have // javascript, then we'll never be able to enter the other textelse if (!$is_multiple) {$disable_js = <<<EOT<script type="text/javascript">//<![CDATA[_qf_altselect_disableElement(document.getElementById('$other_id'),true);//]]></script>EOT;

/** * Exports the value. * * If the other value is set, this will be exported if in singular mode * and the other radio button is selected. Otherwise if in multiple mode * the other value is added to the array of values. * * @param array $submitValues submitValues values submitted * @param bool $assoc propagate on to * HTML_QuickForm_select::exportValue() * @access public * @return mixed Single value or array of values */function exportValue(&$submitValues, $assoc = false) { if (!$this->includeOther) { return parent::exportValue($submitValues, $assoc); }

/** * Set the selected options. If a non-listed option is specified, it * will go into the other text field. Note at this point, the other and * multiple attributes may not have been set. * * @param mixed $values array or comma delimited string of selected values * @access public * @return void */function setSelected($values) {parent::setSelected($values);

// // we need to do some extra work here in case the other // option will be/has been set... //$other_values = array();

foreach ($this->_values as $value) {// if we are in singular mode and the other button is selected from // the submit values then we'll need to record the real other value // in _otherValueif ($value == '_qf_other') {$myName = $this->getName();

$this->_otherValue = @$_REQUEST[$myName.'_qf_other'];

// we only need to grasp the first other value, because we // are in singular mode, so we'll return...return; }// otherwise the real other value might be listed in _values // from setSelected('junk') or if we're in multiple mode and it was // submitted... // if we find something not part of the options then we record it in // _otherValue and set the _qf_other as part of the valueselse {$found = false; foreach ($this->_options as $option) { if ((string) $value == (string) $option['attr']['value']) {$found = true; } }

/** * Returns the name of this element. Used by HTML_QuickForm::getSubmitValue() * when this element is registered as a group. * * @see HTML_QuickForm::getSubmitValue() * @access public * @return string */function getElementName() { return $this->getName(); }

// }}}}

// }}}

if (class_exists('HTML_QuickForm')) {HTML_QuickForm::registerElementType('altselect','HTML/QuickForm/altselect.php','HTML_QuickForm_altselect');}