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

📄 form.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
     * Add prefix paths for all elements     *      * @param  array $spec      * @return Zend_Form     */    public function addElementPrefixPaths(array $spec)    {        $this->_elementPrefixPaths = $this->_elementPrefixPaths + $spec;        foreach ($this->getElements() as $element) {            $element->addPrefixPaths($spec);        }        return $this;    }    /**     * Add prefix path for all display groups     *      * @param  string $prefix      * @param  string $path      * @return Zend_Form     */    public function addDisplayGroupPrefixPath($prefix, $path)    {        $this->_displayGroupPrefixPaths[] = array($prefix, $path);        foreach ($this->getDisplayGroups() as $group) {            $group->addPrefixPath($prefix, $path);        }        return $this;    }    // Form metadata:        /**     * Set form attribute     *      * @param  string $key      * @param  mixed $value      * @return Zend_Form     */    public function setAttrib($key, $value)    {        $key = (string) $key;        $this->_attribs[$key] = $value;        return $this;    }    /**     * Add multiple form attributes at once     *      * @param  array $attribs      * @return Zend_Form     */    public function addAttribs(array $attribs)    {        foreach ($attribs as $key => $value) {            $this->setAttrib($key, $value);        }        return $this;    }    /**     * Set multiple form attributes at once     *     * Overwrites any previously set attributes.     *      * @param  array $attribs      * @return Zend_Form     */    public function setAttribs(array $attribs)    {        $this->clearAttribs();        return $this->addAttribs($attribs);    }    /**     * Retrieve a single form attribute     *      * @param  string $key      * @return mixed     */    public function getAttrib($key)    {        $key = (string) $key;        if (!isset($this->_attribs[$key])) {            return null;        }        return $this->_attribs[$key];    }    /**     * Retrieve all form attributes/metadata     *      * @return array     */    public function getAttribs()    {        return $this->_attribs;    }    /**     * Remove attribute     *      * @param  string $key      * @return bool     */    public function removeAttrib($key)    {        if (isset($this->_attribs[$key])) {            unset($this->_attribs[$key]);            return true;        }        return false;    }    /**     * Clear all form attributes     *      * @return Zend_Form     */    public function clearAttribs()    {        $this->_attribs = array();        return $this;    }    /**     * Set form action     *      * @param  string $action      * @return Zend_Form     */    public function setAction($action)    {        return $this->setAttrib('action', (string) $action);    }    /**     * Get form action     *     * Sets default to '' if not set.     *      * @return string     */    public function getAction()    {        $action = $this->getAttrib('action');        if (null === $action) {            $action = '';            $this->setAction($action);        }        return $action;    }    /**     * Set form method     *     * Only values in {@link $_methods()} allowed     *      * @param  string $method      * @return Zend_Form     * @throws Zend_Form_Exception     */    public function setMethod($method)    {        $method = strtolower($method);        if (!in_array($method, $this->_methods)) {            require_once 'Zend/Form/Exception.php';            throw new Zend_Form_Exception(sprintf('"%s" is an invalid form method', $method));        }        $this->setAttrib('method', $method);        return $this;    }    /**     * Retrieve form method     *      * @return string     */    public function getMethod()    {        if (null === ($method = $this->getAttrib('method'))) {            $method = self::METHOD_POST;            $this->setAttrib('method', $method);        }        return strtolower($method);    }    /**     * Filter a name to only allow valid variable characters     *      * @param  string $value      * @param  bool $allowBrackets     * @return string     */    public function filterName($value, $allowBrackets = false)    {        $charset = '^a-zA-Z0-9_\x7f-\xff';        if ($allowBrackets) {            $charset .= '\[\]';        }        return preg_replace('/[' . $charset . ']/', '', (string) $value);    }    /**     * Set form name     *      * @param  string $name      * @return Zend_Form     */    public function setName($name)    {        $name = $this->filterName($name);        if (('0' !== $name) && empty($name)) {            require_once 'Zend/Form/Exception.php';            throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty');        }        return $this->setAttrib('name', $name);    }    /**     * Get name attribute     *      * @return null|string     */    public function getName()    {        return $this->getAttrib('name');    }    /**     * Set form legend     *      * @param  string $value      * @return Zend_Form     */    public function setLegend($value)    {        $this->_legend = (string) $value;        return $this;    }    /**     * Get form legend     *      * @return string     */    public function getLegend()    {        return $this->_legend;    }    /**     * Set form description     *      * @param  string $value      * @return Zend_Form     */    public function setDescription($value)    {        $this->_description = (string) $value;        return $this;    }    /**     * Retrieve form description     *      * @return string     */    public function getDescription()    {        return $this->_description;    }    /**     * Set form order     *      * @param  int $index      * @return Zend_Form     */    public function setOrder($index)    {        $this->_formOrder = (int) $index;        return $this;    }    /**     * Get form order     *      * @return int|null     */    public function getOrder()    {        return $this->_formOrder;    }     // Element interaction:     /**     * Add a new element     *     * $element may be either a string element type, or an object of type      * Zend_Form_Element. If a string element type is provided, $name must be      * provided, and $options may be optionally provided for configuring the      * element.     *     * If a Zend_Form_Element is provided, $name may be optionally provided,      * and any provided $options will be ignored.     *      * @param  string|Zend_Form_Element $element      * @param  string $name      * @param  array|Zend_Config $options      * @return Zend_Form     */    public function addElement($element, $name = null, $options = null)    {        if (is_string($element)) {            if (null === $name) {                require_once 'Zend/Form/Exception.php';                throw new Zend_Form_Exception('Elements specified by string must have an accompanying name');            }            $this->_elements[$name] = $this->createElement($element, $name, $options);        } elseif ($element instanceof Zend_Form_Element) {            $prefixPaths              = array();            $prefixPaths['decorator'] = $this->getPluginLoader('decorator')->getPaths();            if (!empty($this->_elementPrefixPaths)) {                $prefixPaths = array_merge($prefixPaths, $this->_elementPrefixPaths);            }            if (null === $name) {                $name = $element->getName();            }            $this->_elements[$name] = $element;            $this->_elements[$name]->addPrefixPaths($prefixPaths);        }        $this->_order[$name] = $this->_elements[$name]->getOrder();        $this->_orderUpdated = true;        return $this;    }    /**     * Create an element     *     * Acts as a factory for creating elements. Elements created with this      * method will not be attached to the form, but will contain element      * settings as specified in the form object (including plugin loader      * prefix paths, default decorators, etc.).     *      * @param  string $type      * @param  string $name      * @param  array|Zend_Config $options      * @return Zend_Form_Element     */    public function createElement($type, $name, $options = null)    {        if (!is_string($type)) {            require_once 'Zend/Form/Exception.php';            throw new Zend_Form_Exception('Element type must be a string indicating type');        }        if (!is_string($name)) {            require_once 'Zend/Form/Exception.php';            throw new Zend_Form_Exception('Element name must be a string');        }        $prefixPaths              = array();        $prefixPaths['decorator'] = $this->getPluginLoader('decorator')->getPaths();        if (!empty($this->_elementPrefixPaths)) {            $prefixPaths = array_merge($prefixPaths, $this->_elementPrefixPaths);        }        if ($options instanceof Zend_Config) {            $options = $options->toArray();        }        if ((null === $options) || !is_array($options)) {            $options = array('prefixPath' => $prefixPaths);        } elseif (is_array($options)) {            if (array_key_exists('prefixPath', $options)) {                $options['prefixPath'] = array_merge($prefixPaths, $options['prefixPath']);            } else {                $options['prefixPath'] = $prefixPaths;            }        }        $class = $this->getPluginLoader(self::ELEMENT)->load($type);        $element = new $class($name, $options);        return $element;    }    /**     * Add multiple elements at once     *      * @param  array $elements      * @return Zend_Form     */    public function addElements(array $elements)    {        foreach ($elements as $key => $spec) {            $name = null;            if (!is_numeric($key)) {                $name = $key;            }            if (is_string($spec) || ($spec instanceof Zend_Form_Element)) {                $this->addElement($spec, $name);                continue;            }            if (is_array($spec)) {                $argc = count($spec);                $options = array();                if (isset($spec['type'])) {                    $type = $spec['type'];                    if (isset($spec['name'])) {                        $name = $spec['name'];                    }                    if (isset($spec['options'])) {                        $options = $spec['options'];                    }                    $this->addElement($type, $name, $options);                } else {                    switch ($argc) {                        case 0:                            continue;                        case (1 <= $argc):                            $type = array_shift($spec);                        case (2 <= $argc):                            if (null === $name) {                                $name = array_shift($spec);                            } else {                                $options = array_shift($spec);                            }                        case (3 <= $argc):                            if (empty($options)) {                                $options = array_shift($spec);                            }                        default:                            $this->addElement($type, $name, $options);                    }                }            }        }        return $this;    }    /**     * Set form elements (overwrites existing elements)     *      * @param  array $elements      * @return Zend_Form     */    public function setElements(array $elements)    {        $this->clearElements();        return $this->addElements($elements);    }    /**     * Retrieve a single element     *      * @param  string $name      * @return Zend_Form_Element|null     */    public function getElement($name)    {        if (isset($this->_elements[$name])) {            return $this->_elements[$name];

⌨️ 快捷键说明

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