form.php.svn-base
来自「j2me is based on j2mepolish, client & se」· SVN-BASE 代码 · 共 491 行 · 第 1/2 页
SVN-BASE
491 行
<?php/* SVN FILE: $Id: form.php 4050 2006-12-02 03:49:35Z phpnut $ *//** * Automatic generation of HTML FORMs from given data. * * Used for scaffolding. * * PHP versions 4 and 5 * * CakePHP : Rapid Development Framework <http://www.cakephp.org/> * Copyright (c) 2006, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package cake * @subpackage cake.cake.libs.view.helpers * @since CakePHP v 0.10.0.1076 * @version $Revision: 4050 $ * @modifiedby $LastChangedBy: phpnut $ * @lastmodified $Date: 2006-12-01 21:49:35 -0600 (Fri, 01 Dec 2006) $ * @license http://www.opensource.org/licenses/mit-license.php The MIT License *//** * Tag template for a div with a class attribute. */ define('TAG_DIV', '<div class="%s">%s</div>');/** * Tag template for a paragraph with a class attribute. */ define('TAG_P_CLASS', '<p class="%s">%s</p>');/** * Tag template for a label with a for attribute. */ define('TAG_LABEL', '<label for="%s">%s</label>');/** * Tag template for a fieldset with a legend tag inside. */ define('TAG_FIELDSET', '<fieldset><legend>%s</legend>%s</label>');/** * Form helper library. * * Automatic generation of HTML FORMs from given data. * * @package cake * @subpackage cake.cake.libs.view.helpers */class FormHelper extends Helper{/** * Included helpers. * * @var array * @access public */ var $helpers = array('Html');/** * Returns a formatted error message for given FORM field, NULL if no errors. * * @param string $field This should be "Modelname/fieldname" * @return bool If there are errors this method returns true, else false. * @access public */ function isFieldError($field) { $error=1; $this->Html->setFormTag($field); if ($error == $this->Html->tagIsInvalid($this->Html->model, $this->Html->field)) { return true; } else { return false; } }/** * Returns a formatted LABEL element for HTML FORMs. * * @param string $tagName This should be "Modelname/fieldname" * @param string $text Text that will appear in the label field. * @return string The formatted LABEL element * @access public */ function labelTag($tagName, $text) { return sprintf(TAG_LABEL, Inflector::camelize(str_replace('/', '_', $tagName)), $text); }/** * Returns a formatted DIV tag for HTML FORMs. * * @param string $class CSS class name of the div element. * @param string $text String content that will appear inside the div element. * @return string The formatted DIV element * @access public */ function divTag($class, $text) { return sprintf(TAG_DIV, $class, $text); }/** * Returns a formatted P tag with class for HTML FORMs. * * @param string $class CSS class name of the p element. * @param string $text Text that will appear inside the p element. * @return string The formatted P element * @access public */ function pTag($class, $text) { return sprintf(TAG_P_CLASS, $class, $text); }/** * Returns a formatted INPUT tag for HTML FORMs. * * @param string $tagName This should be "Modelname/fieldname" * @param string $prompt Text that will appear in the label field. * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. * @param int $size Size attribute for INPUT element * @param array $htmlOptions HTML options array. * @return string The formatted INPUT element, with a label and wrapped in a div. * @access public */ function generateInputDiv($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null) { $htmlAttributes = $htmlOptions; $htmlAttributes['size'] = $size; $str = $this->Html->input($tagName, $htmlAttributes); $strLabel = $this->labelTag($tagName, $prompt); $divClass = "optional"; if ($required) { $divClass = "required"; } $strError = ""; if ($this->isFieldError($tagName)) { $strError = $this->pTag('error', $errorMsg); $divClass = sprintf("%s error", $divClass); } $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str); return $this->divTag($divClass, $divTagInside); }/** * Returns a formatted CHECKBOX tag inside a DIV for HTML FORMs. * * @param string $tagName This should be "Modelname/fieldname" * @param string $prompt Text that will appear in the label field. * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. * @param array $htmlOptions HTML options array. * @return string The formatted checkbox div * @access public */ function generateCheckboxDiv($tagName, $prompt, $required = false, $errorMsg = null, $htmlOptions = null) { $htmlOptions['class'] = "inputCheckbox"; $str = $this->Html->checkbox($tagName, null, $htmlOptions); $strLabel = $this->labelTag($tagName, $prompt); $divClass = "optional"; if ($required) { $divClass = "required"; } $strError = ""; if ($this->isFieldError($tagName)) { $strError = $this->pTag('error', $errorMsg); $divClass = sprintf("%s error", $divClass); } $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str); return $this->divTag($divClass, $divTagInside); }/** * Returns a formatted date option element for HTML FORMs. * * @param string $tagName This should be "Modelname/fieldname" * @param string $prompt Text that will appear in the label field. * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. * @param int $size Not used. * @param array $htmlOptions HTML options array * @return string Date option wrapped in a div. * @todo Remove the $size parameter from this method. * @access public */ function generateDate($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) { $str = $this->Html->dateTimeOptionTag($tagName, 'MDY', 'NONE', $selected, $htmlOptions); $strLabel = $this->labelTag($tagName, $prompt); $divClass = "optional"; if ($required) { $divClass = "required"; } $strError = ""; if ($this->isFieldError($tagName)) { $strError = $this->pTag('error', $errorMsg); $divClass = sprintf("%s error", $divClass); } $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str); $requiredDiv = $this->divTag($divClass, $divTagInside); return $this->divTag("date", $requiredDiv); }/** * Returns a formatted date option element for HTML FORMs. * * @param string $tagName This should be "Modelname/fieldname" * @param string $prompt Text that will appear in the label field. * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. * @param int $size Not used. * @param array $htmlOptions HTML options array * @return string Date option wrapped in a div. * @todo Remove the $size parameter from this method. * @access public */ function generateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) { $str = $this->Html->dateTimeOptionTag($tagName, 'NONE', '24', $selected, $htmlOptions); $strLabel = $this->labelTag($tagName, $prompt); $divClass = "optional"; if ($required) { $divClass = "required"; } $strError = ""; if ($this->isFieldError($tagName)) { $strError = $this->pTag('error', $errorMsg); $divClass = sprintf("%s error", $divClass); } $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str); $requiredDiv = $this->divTag($divClass, $divTagInside); return $this->divTag("time", $requiredDiv); }/** * Returns a formatted year option element for HTML FORMs. * * @param string $tagName This should be "Modelname/fieldname" * @param string $prompt Text that will appear in the label field. * @param bool $required True if this field is a required field. * @param string $errorMsg Text that will appear if an error has occurred. * @param int $size Not used. * @param array $htmlOptions HTML options array * @return string Date option wrapped in a div. * @todo Remove the $size parameter from this method. * @access public */ function generateYear($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) { $str = $this->Html->dateTimeOptionTag($tagName, 'Y', 'NONE', $selected, $htmlOptions); $strLabel = $this->labelTag($tagName, $prompt); $divClass = "optional"; if ($required) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?