📄 quickform.php
字号:
<?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: QuickForm.php 14987 2008-04-21 17:14:12Z juliomontoya $require_once('PEAR.php');require_once('HTML/Common.php');$GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array( 'group' =>array('HTML/QuickForm/group.php','HTML_QuickForm_group'), 'hidden' =>array('HTML/QuickForm/hidden.php','HTML_QuickForm_hidden'), 'reset' =>array('HTML/QuickForm/reset.php','HTML_QuickForm_reset'), 'checkbox' =>array('HTML/QuickForm/checkbox.php','HTML_QuickForm_checkbox'), 'file' =>array('HTML/QuickForm/file.php','HTML_QuickForm_file'), 'image' =>array('HTML/QuickForm/image.php','HTML_QuickForm_image'), 'password' =>array('HTML/QuickForm/password.php','HTML_QuickForm_password'), 'radio' =>array('HTML/QuickForm/radio.php','HTML_QuickForm_radio'), 'button' =>array('HTML/QuickForm/button.php','HTML_QuickForm_button'), 'submit' =>array('HTML/QuickForm/submit.php','HTML_QuickForm_submit'), 'select' =>array('HTML/QuickForm/select.php','HTML_QuickForm_select'), 'hiddenselect' =>array('HTML/QuickForm/hiddenselect.php','HTML_QuickForm_hiddenselect'), 'text' =>array('HTML/QuickForm/text.php','HTML_QuickForm_text'), 'textarea' =>array('HTML/QuickForm/textarea.php','HTML_QuickForm_textarea'), 'link' =>array('HTML/QuickForm/link.php','HTML_QuickForm_link'), 'advcheckbox' =>array('HTML/QuickForm/advcheckbox.php','HTML_QuickForm_advcheckbox'), 'date' =>array('HTML/QuickForm/date.php','HTML_QuickForm_date'), 'static' =>array('HTML/QuickForm/static.php','HTML_QuickForm_static'), 'header' =>array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'), 'html' =>array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'), 'hierselect' =>array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'), 'autocomplete' =>array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'), 'xbutton' =>array('HTML/QuickForm/xbutton.php','HTML_QuickForm_xbutton') );$GLOBALS['_HTML_QuickForm_registered_rules'] = array( 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'), 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'), 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'));// {{{ error codes/* * Error codes for the QuickForm interface, which will be mapped to textual messages * in the QuickForm::errorMessage() function. If you are to add a new error code, be * sure to add the textual messages to the QuickForm::errorMessage() function as well */define('QUICKFORM_OK', 1);define('QUICKFORM_ERROR', -1);define('QUICKFORM_INVALID_RULE', -2);define('QUICKFORM_NONEXIST_ELEMENT', -3);define('QUICKFORM_INVALID_FILTER', -4);define('QUICKFORM_UNREGISTERED_ELEMENT', -5);define('QUICKFORM_INVALID_ELEMENT_NAME', -6);define('QUICKFORM_INVALID_PROCESS', -7);define('QUICKFORM_DEPRECATED', -8);define('QUICKFORM_INVALID_DATASOURCE', -9);// }}}/*** Create, validate and process HTML forms** @author Adam Daniel <adaniel1@eesus.jnj.com>* @author Bertrand Mansion <bmansion@mamasam.com>* @version 2.0* @since PHP 4.0.3pl1*/class HTML_QuickForm extends HTML_Common { // {{{ properties /** * Array containing the form fields * @since 1.0 * @var array * @access private */ var $_elements = array(); /** * Array containing element name to index map * @since 1.1 * @var array * @access private */ var $_elementIndex = array(); /** * Array containing indexes of duplicate elements * @since 2.10 * @var array * @access private */ var $_duplicateIndex = array(); /** * Array containing required field IDs * @since 1.0 * @var array * @access private */ var $_required = array(); /** * Prefix message in javascript alert if error * @since 1.0 * @var string * @access public */ var $_jsPrefix = 'Invalid information entered.'; /** * Postfix message in javascript alert if error * @since 1.0 * @var string * @access public */ var $_jsPostfix = 'Please correct these fields.'; /** * Datasource object implementing the informal * datasource protocol * @since 3.3 * @var object * @access private */ var $_datasource; /** * Array of default form values * @since 2.0 * @var array * @access private */ var $_defaultValues = array(); /** * Array of constant form values * @since 2.0 * @var array * @access private */ var $_constantValues = array(); /** * Array of submitted form values * @since 1.0 * @var array * @access private */ var $_submitValues = array(); /** * Array of submitted form files * @since 1.0 * @var integer * @access public */ var $_submitFiles = array(); /** * Value for maxfilesize hidden element if form contains file input * @since 1.0 * @var integer * @access public */ var $_maxFileSize = 1048576; // 1 Mb = 1048576 /** * Flag to know if all fields are frozen * @since 1.0 * @var boolean * @access private */ var $_freezeAll = false; /** * Array containing the form rules * @since 1.0 * @var array * @access private */ var $_rules = array(); /** * Form rules, global variety * @var array * @access private */ var $_formRules = array(); /** * Array containing the validation errors * @since 1.0 * @var array * @access private */ var $_errors = array(); /** * Note for required fields in the form * @var string * @since 1.0 * @access private */ var $_requiredNote = '<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;"> denotes required field</span>'; /** * Whether the form was submitted * @var boolean * @access private */ var $_flagSubmitted = false; // }}} // {{{ constructor /** * Class constructor * @param string $formName Form's name. * @param string $method (optional)Form's method defaults to 'POST' * @param string $action (optional)Form's action * @param string $target (optional)Form's target defaults to '_self' * @param mixed $attributes (optional)Extra attributes for <form> tag * @param bool $trackSubmit (optional)Whether to track if the form was submitted by adding a special hidden field * @access public */ function HTML_QuickForm($formName='', $method='post', $action='', $target='', $attributes=null, $trackSubmit = false) { HTML_Common::HTML_Common($attributes); $method = (strtoupper($method) == 'GET') ? 'get' : 'post'; $action = ($action == '') ? api_get_self() : $action; $target = empty($target) ? array() : array('target' => $target); $attributes = array('action'=>$action, 'method'=>$method, 'name'=>$formName, 'id'=>$formName) + $target; $this->updateAttributes($attributes); if (!$trackSubmit || isset($_REQUEST['_qf__' . $formName])) { if (1 == get_magic_quotes_gpc()) { $this->_submitValues = $this->_recursiveFilter('stripslashes', 'get' == $method? $_GET: $_POST); foreach ($_FILES as $keyFirst => $valFirst) { foreach ($valFirst as $keySecond => $valSecond) { if ('name' == $keySecond) { $this->_submitFiles[$keyFirst][$keySecond] = $this->_recursiveFilter('stripslashes', $valSecond); } else { $this->_submitFiles[$keyFirst][$keySecond] = $valSecond; } } } } else { $this->_submitValues = 'get' == $method? $_GET: $_POST; $this->_submitFiles = $_FILES; } $this->_flagSubmitted = count($this->_submitValues) > 0 || count($this->_submitFiles) > 0; } if ($trackSubmit) { unset($this->_submitValues['_qf__' . $formName]); $this->addElement('hidden', '_qf__' . $formName, null); } if (preg_match('/^([0-9]+)([a-zA-Z]*)$/', ini_get('upload_max_filesize'), $matches)) { // see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes switch (strtoupper($matches['2'])) { case 'G': $this->_maxFileSize = $matches['1'] * 1073741824; break; case 'M': $this->_maxFileSize = $matches['1'] * 1048576; break; case 'K': $this->_maxFileSize = $matches['1'] * 1024; break; default: $this->_maxFileSize = $matches['1']; } } } // end constructor // }}} // {{{ apiVersion() /** * Returns the current API version * * @since 1.0 * @access public * @return float */ function apiVersion() { return 3.2; } // end func apiVersion // }}} // {{{ registerElementType() /** * Registers a new element type * * @param string $typeName Name of element type * @param string $include Include path for element type * @param string $className Element class name * @since 1.0 * @access public * @return void */ function registerElementType($typeName, $include, $className) { $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][strtolower($typeName)] = array($include, $className); } // end func registerElementType // }}} // {{{ registerRule()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -