Source for file Default.php
Documentation is available at Default.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | 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: Alexey Borzov <borz_off@cs.msu.su> |
// | Adam Daniel <adaniel1@eesus.jnj.com> |
// | Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
require_once('HTML/QuickForm/Renderer.php');
* A concrete renderer for HTML_QuickForm,
* based on QuickForm 2.x built-in one
"\n\t<tr>\n\t\t<td style=\"white-space: nowrap; background-color: #CCCCCC;\" align=\"left\" valign=\"top\" colspan=\"2\"><b>{header}</b></td>\n\t</tr>";
* Element template string
"\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>";
"\n<form{attributes}>\n<div>\n{hidden}<table border=\"0\">\n{content}\n</table>\n</div>\n</form>";
* Required Note template string
var $_requiredNoteTemplate =
"\n\t<tr>\n\t\t<td></td>\n\t<td align=\"left\" valign=\"top\">{requiredNote}</td>\n\t</tr>";
* Array containing the templates for customised elements
var $_templates = array ();
* Array containing the templates for group wraps.
* These templates are wrapped around group elements and groups' own
* templates wrap around them. This is set by setGroupTemplate().
var $_groupWraps = array ();
* Array containing the templates for elements within groups
var $_groupTemplates = array ();
* True if we are inside a group
* Array with HTML generated for group elements
var $_groupElements = array ();
* Template for an element inside a group
var $_groupElementTemplate = '';
* HTML that wraps around the group elements
* HTML for the current group
var $_groupTemplate = '';
* Collected HTML of the hidden fields
$this->HTML_QuickForm_Renderer ();
* returns the HTML generated for the form
// _hiddenHtml is cleared in finishForm(), so this only matters when
// finishForm() was not called (e.g. group::toHtml(), bug #3511)
return $this->_hiddenHtml . $this->_html;
* Called when visiting a form, before processing any form elements
* @param object An HTML_QuickForm object being visited
* Called when visiting a form, after processing all form elements
* Adds required note, form attributes, validation javascript and form content.
* @param object An HTML_QuickForm object being visited
// add a required note, if one is needed
if (!empty ($form->_required ) && !$form->_freezeAll ) {
$this->_html .= str_replace('{requiredNote}', $form->getRequiredNote (), $this->_requiredNoteTemplate);
// add form attributes and content
$html = str_replace('{attributes}', $form->getAttributes (true ), $this->_formTemplate);
if (strpos($this->_formTemplate, '{hidden}')) {
$html = str_replace('{hidden}', $this->_hiddenHtml, $html);
$this->_html .= $this->_hiddenHtml;
$this->_html = str_replace('{content}', $this->_html, $html);
// add a validation script
if ('' != ($script = $form->getValidationScript ())) {
$this->_html = $script . "\n" . $this->_html;
* Called when visiting a header element
* @param object An HTML_QuickForm_header element being visited
$name = $header->getName ();
if (!empty ($name) && isset ($this->_templates[$name])) {
$this->_html .= str_replace('{header}', $header->toHtml (), $this->_templates[$name]);
$this->_html .= str_replace('{header}', $header->toHtml (), $this->_headerTemplate);
} // end func renderHeader
* Helper method for renderElement
* @param string Element name
* @param mixed Element label (if using an array of labels, you should set the appropriate template)
* @param bool Whether an element is required
* @param string Error message associated with the element
* @return string Html for element
function _prepareTemplate ($name, $label, $required, $error)
if (isset ($this->_templates[$name])) {
$html = str_replace('{label}', $nameLabel, $this->_templates[$name]);
$html = str_replace('{label}', $nameLabel, $this->_elementTemplate);
$html = str_replace('<!-- BEGIN required -->', '', $html);
$html = str_replace('<!-- END required -->', '', $html);
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
$html = str_replace('<!-- BEGIN error -->', '', $html);
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->(\s|\S)*<!-- END error -->([ \t\n\r]*)?/i", '', $html);
foreach($label as $key => $text) {
$key = is_int($key)? $key + 2: $key;
$html = str_replace(" <!-- BEGIN label_{$key} -->" , '', $html);
$html = str_replace(" <!-- END label_{$key} -->" , '', $html);
if (strpos($html, '{label_')) {
$html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/i', '', $html);
} // end func _prepareTemplate
* Renders an element Html
* 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
$html = $this->_prepareTemplate ($element->getName (), $element->getLabel (), $required, $error);
$this->_html .= str_replace('{element}', $element->toHtml (), $html);
} elseif (!empty ($this->_groupElementTemplate)) {
$html = str_replace('{label}', $element->getLabel (), $this->_groupElementTemplate);
$html = str_replace('<!-- BEGIN required -->', '', $html);
$html = str_replace('<!-- END required -->', '', $html);
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
$this->_groupElements[] = str_replace('{element}', $element->toHtml (), $html);
$this->_groupElements[] = $element->toHtml ();
} // end func renderElement
* Renders an hidden element
* Called when visiting a hidden element
* @param object An HTML_QuickForm_hidden object being visited
$this->_hiddenHtml .= $element->toHtml () . "\n";
} // end func renderHidden
* Called when visiting a raw HTML/text pseudo-element
* @param object An HTML_QuickForm_html element being visited
$this->_html .= $data->toHtml ();
* Called when visiting a group, before processing any group elements
* @param object An HTML_QuickForm_group object being visited
* @param bool Whether a group is required
* @param string An error message associated with a group
$name = $group->getName ();
$this->_groupTemplate = $this->_prepareTemplate ($name, $group->getLabel (), $required, $error);
$this->_groupElementTemplate = empty ($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name];
$this->_groupWrap = empty ($this->_groupWraps[$name])? '': $this->_groupWraps[$name];
$this->_groupElements = array ();
* Called when visiting a group, after processing all group elements
* @param object An HTML_QuickForm_group object being visited
$separator = $group->_separator;
$count = count($separator);
for ($i = 0; $i < count($this->_groupElements); $i++ ) {
$html .= (0 == $i? '': $separator[($i - 1 ) % $count]) . $this->_groupElements[$i];
$html = implode((string) $separator, $this->_groupElements);
if (!empty ($this->_groupWrap)) {
$html = str_replace('{content}', $html, $this->_groupWrap);
$this->_html .= str_replace('{element}', $html, $this->_groupTemplate);
} // end func finishGroup
* @param string The HTML surrounding an element
* @param string (optional) Name of the element to apply template for
$this->_elementTemplate = $html;
$this->_templates[$element] = $html;
} // end func setElementTemplate
* Sets template for a group wrapper
* This template is contained within a group-as-element template
* set via setTemplate() and contains group's element templates, set
* via setGroupElementTemplate()
* @param string The HTML surrounding group elements
* @param string Name of the group to apply template for
$this->_groupWraps[$group] = $html;
} // end func setGroupTemplate
* Sets element template for elements within a group
* @param string The HTML surrounding an element
* @param string Name of the group to apply template for
$this->_groupTemplates[$group] = $html;
} // end func setGroupElementTemplate
* @param string The HTML surrounding the header
$this->_headerTemplate = $html;
} // end func setHeaderTemplate
* @param string The HTML surrounding the form tags
$this->_formTemplate = $html;
} // end func setFormTemplate
* Sets the note indicating required fields template
* @param string The HTML surrounding the required note
$this->_requiredNoteTemplate = $html;
} // end func setRequiredNoteTemplate
* Clears all the HTML out of the templates that surround notes, elements, etc.
* Useful when you want to use addData() to create a completely custom form look
$this->_templates = array ();
} // end func clearAllTemplates
} // end class HTML_QuickForm_Renderer_Default
Documentation generated on Mon, 11 Mar 2019 14:16:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|