📄 select.php
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: *//** * Class to dynamically create an HTML SELECT * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.01 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_01.txt If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category HTML * @package HTML_QuickForm * @author Adam Daniel <adaniel1@eesus.jnj.com> * @author Bertrand Mansion <bmansion@mamasam.com> * @author Alexey Borzov <avb@php.net> * @copyright 2001-2007 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: select.php 444 2008-04-11 13:38:22Z johmathe $ * @link http://pear.php.net/package/HTML_QuickForm *//** * Base class for form elements */ require_once 'HTML/QuickForm/element.php';/** * Class to dynamically create an HTML SELECT * * @category HTML * @package HTML_QuickForm * @author Adam Daniel <adaniel1@eesus.jnj.com> * @author Bertrand Mansion <bmansion@mamasam.com> * @author Alexey Borzov <avb@php.net> * @version Release: 3.2.9 * @since 1.0 */class HTML_QuickForm_select extends HTML_QuickForm_element { // {{{ properties /** * Contains the select options * * @var array * @since 1.0 * @access private */ var $_options = array(); /** * Default values of the SELECT * * @var string * @since 1.0 * @access private */ var $_values = null; // }}} // {{{ constructor /** * Class constructor * * @param string Select name attribute * @param mixed Label(s) for the select * @param mixed Data to be used to populate options * @param mixed Either a typical HTML attribute string or an associative array * @since 1.0 * @access public * @return void */ function HTML_QuickForm_select($elementName=null, $elementLabel=null, $options=null, $attributes=null) { HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'select'; if (isset($options)) { $this->load($options); } } //end constructor // }}} // {{{ apiVersion() /** * Returns the current API version * * @since 1.0 * @access public * @return double */ function apiVersion() { return 2.3; } //end func apiVersion // }}} // {{{ setSelected() /** * Sets the default values of the select box * * @param mixed $values Array or comma delimited string of selected values * @since 1.0 * @access public * @return void */ function setSelected($values) { if (is_string($values) && $this->getMultiple()) { $values = split("[ ]?,[ ]?", $values); } if (is_array($values)) { $this->_values = array_values($values); } else { $this->_values = array($values); } } //end func setSelected // }}} // {{{ getSelected() /** * Returns an array of the selected values * * @since 1.0 * @access public * @return array of selected values */ function getSelected() { return $this->_values; } // end func getSelected // }}} // {{{ setName() /** * Sets the input field name * * @param string $name Input field name attribute * @since 1.0 * @access public * @return void */ function setName($name) { $this->updateAttributes(array('name' => $name)); } //end func setName // }}} // {{{ getName() /** * Returns the element name * * @since 1.0 * @access public * @return string */ function getName() { return $this->getAttribute('name'); } //end func getName // }}} // {{{ getPrivateName() /** * Returns the element name (possibly with brackets appended) * * @since 1.0 * @access public * @return string */ function getPrivateName() { if ($this->getAttribute('multiple')) { return $this->getName() . '[]'; } else { return $this->getName(); } } //end func getPrivateName // }}} // {{{ setValue() /** * Sets the value of the form element * * @param mixed $values Array or comma delimited string of selected values * @since 1.0 * @access public * @return void */ function setValue($value) { $this->setSelected($value); } // end func setValue // }}} // {{{ getValue() /** * Returns an array of the selected values * * @since 1.0 * @access public * @return array of selected values */ function getValue() { return $this->_values; } // end func getValue // }}} // {{{ setSize() /** * Sets the select field size, only applies to 'multiple' selects * * @param int $size Size of select field * @since 1.0 * @access public * @return void */ function setSize($size) { $this->updateAttributes(array('size' => $size)); } //end func setSize // }}} // {{{ getSize() /** * Returns the select field size * * @since 1.0 * @access public * @return int */ function getSize() { return $this->getAttribute('size'); } //end func getSize // }}} // {{{ setMultiple() /** * Sets the select mutiple attribute * * @param bool $multiple Whether the select supports multi-selections * @since 1.2 * @access public * @return void */ function setMultiple($multiple) { if ($multiple) { $this->updateAttributes(array('multiple' => 'multiple')); } else { $this->removeAttribute('multiple'); } } //end func setMultiple // }}} // {{{ getMultiple() /** * Returns the select mutiple attribute * * @since 1.2 * @access public * @return bool true if multiple select, false otherwise */ function getMultiple() { return (bool)$this->getAttribute('multiple'); } //end func getMultiple // }}} // {{{ addOption() /** * Adds a new OPTION to the SELECT * * @param string $text Display text for the OPTION * @param string $value Value for the OPTION * @param mixed $attributes Either a typical HTML attribute string * or an associative array * @since 1.0 * @access public * @return void */ function addOption($text, $value, $attributes=null) { if (null === $attributes) { $attributes = array('value' => (string)$value); } else { $attributes = $this->_parseAttributes($attributes); if (isset($attributes['selected'])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -