📄 itstatic.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. |// +----------------------------------------------------------------------+// | Author: Bertrand Mansion <bmansion@mamasam.com> |// +----------------------------------------------------------------------+//// $Id: ITStatic.php 6184 2005-09-07 10:08:17Z bmol $require_once('HTML/QuickForm/Renderer.php');/** * A static renderer for HTML_QuickForm compatible * with HTML_Template_IT and HTML_Template_Sigma. * * As opposed to the dynamic renderer, this renderer needs * every elements and labels in the form to be specified by * placeholders at the position you want them to be displayed. * * @author Bertrand Mansion <bmansion@mamasam.com> * @access public */class HTML_QuickForm_Renderer_ITStatic extends HTML_QuickForm_Renderer{ /** * An HTML_Template_IT or some other API compatible Template instance * @var object */ var $_tpl = null; /** * Rendered form name * @var string */ var $_formName = 'form'; /** * The errors that were not shown near concrete fields go here * @var array */ var $_errors = array(); /** * Show the block with required note? * @var bool */ var $_showRequired = false; /** * Which group are we currently parsing ? * @var string */ var $_inGroup; /** * Index of the element in its group * @var int */ var $_elementIndex = 0; /** * If elements have been added with the same name * @var array */ var $_duplicateElements = array(); /** * How to handle the required tag for required fields * @var string */ var $_required = '{label}<font size="1" color="red">*</font>'; /** * How to handle error messages in form validation * @var string */ var $_error = '<font color="red">{error}</font><br />{html}'; /** * Collected HTML for hidden elements, if needed * @var string */ var $_hidden = ''; /** * Constructor * * @param object An HTML_Template_IT or other compatible Template object to use */ function HTML_QuickForm_Renderer_ITStatic(&$tpl) { $this->HTML_QuickForm_Renderer(); $this->_tpl =& $tpl; } // end constructor /** * Called when visiting a form, before processing any form elements * * @param object An HTML_QuickForm object being visited * @access public * @return void */ function startForm(&$form) { $this->_formName = $form->getAttribute('id'); if (count($form->_duplicateIndex) > 0) { // Take care of duplicate elements foreach ($form->_duplicateIndex as $elementName => $indexes) { $this->_duplicateElements[$elementName] = 0; } } } // end func startForm /** * Called when visiting a form, after processing all form elements * * @param object An HTML_QuickForm object being visited * @access public * @return void */ function finishForm(&$form) { // display errors above form if (!empty($this->_errors) && $this->_tpl->blockExists($this->_formName.'_error_loop')) { foreach ($this->_errors as $error) { $this->_tpl->setVariable($this->_formName.'_error', $error); $this->_tpl->parse($this->_formName.'_error_loop'); } } // show required note if ($this->_showRequired) { $this->_tpl->setVariable($this->_formName.'_required_note', $form->getRequiredNote()); } // add hidden elements, if collected if (!empty($this->_hidden)) { $this->_tpl->setVariable($this->_formName . '_hidden', $this->_hidden); } // assign form attributes $this->_tpl->setVariable($this->_formName.'_attributes', $form->getAttributes(true)); // assign javascript validation rules $this->_tpl->setVariable($this->_formName.'_javascript', $form->getValidationScript()); } // end func finishForm /** * Called when visiting a header element * * @param object An HTML_QuickForm_header element being visited * @access public * @return void */ function renderHeader(&$header) { $name = $header->getName(); $varName = $this->_formName.'_header'; // Find placeHolder if (!empty($name) && $this->_tpl->placeHolderExists($this->_formName.'_header_'.$name)) { $varName = $this->_formName.'_header_'.$name; } $this->_tpl->setVariable($varName, $header->toHtml()); } // end func renderHeader /** * Called when visiting an element * * @param object An HTML_QuickForm_element object being visited * @param bool Whether an element is required * @param string An error message associated with an element * @access public * @return void */ function renderElement(&$element, $required, $error) { $name = $element->getName(); // are we inside a group? if (!empty($this->_inGroup)) { $varName = $this->_formName.'_'.str_replace(array('[', ']'), '_', $name); if (substr($varName, -2) == '__') { // element name is of type : group[] $varName = $this->_inGroup.'_'.$this->_elementIndex.'_'; $this->_elementIndex++; } if ($varName != $this->_inGroup) { $varName .= '_' == substr($varName, -1)? '': '_'; // element name is of type : group[name] $label = $element->getLabel(); $html = $element->toHtml(); if ($required && !$element->isFrozen()) { $this->_renderRequired($label, $html); $this->_showRequired = true; } if (!empty($label)) { if (is_array($label)) { foreach ($label as $key => $value) { $this->_tpl->setVariable($varName.'label_'.$key, $value); } } else { $this->_tpl->setVariable($varName.'label', $label); } } $this->_tpl->setVariable($varName.'html', $html); } } else { $name = str_replace(array('[', ']'), array('_', ''), $name); if (isset($this->_duplicateElements[$name])) { // Element is a duplicate $varName = $this->_formName.'_'.$name.'_'.$this->_duplicateElements[$name]; $this->_duplicateElements[$name]++; } else { $varName = $this->_formName.'_'.$name; } $label = $element->getLabel(); $html = $element->toHtml(); if ($required) { $this->_showRequired = true; $this->_renderRequired($label, $html); } if (!empty($error)) { $this->_renderError($label, $html, $error); } if (is_array($label)) { foreach ($label as $key => $value) { $this->_tpl->setVariable($varName.'_label_'.$key, $value); } } else { $this->_tpl->setVariable($varName.'_label', $label);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -