⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4: */// +----------------------------------------------------------------------+// | PHP version 4.0                                                      |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2003 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: select.php 12243 2007-05-02 21:00:52Z yannoo $require_once('HTML/QuickForm/element.php');/** * Class to dynamically create an HTML SELECT * * @author       Adam Daniel <adaniel1@eesus.jnj.com> * @author       Bertrand Mansion <bmansion@mamasam.com> * @version      1.0 * @since        PHP4.04pl1 * @access       public */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' => $value);        } else {            $attributes = $this->_parseAttributes($attributes);            if (isset($attributes['selected'])) {                // the 'selected' attribute will be set in toHtml()                $this->_removeAttr('selected', $attributes);                if (is_null($this->_values)) {                    $this->_values = array($value);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -