Source for file Tableless.php
Documentation is available at Tableless.php
* Replacement for the default renderer of HTML_QuickForm that uses only XHTML
* and CSS but no table tags, and generates fully valid XHTML output
* LICENSE: This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to wiesemann@php.net so we can send you a copy immediately.
* @package HTML_QuickForm_Renderer_Tableless
* @author Alexey Borzov <borz_off@cs.msu.su>
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @author Mark Wiesemann <wiesemann@php.net>
* @copyright 2005-2006 The PHP Group
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Tableless.php,v 1.19 2006/11/09 21:12:37 wiesemann Exp $
* @link http://pear.php.net/package/HTML_QuickForm_Renderer_Tableless
require_once 'HTML/QuickForm/Renderer/Default.php';
* Replacement for the default renderer of HTML_QuickForm that uses only XHTML
* and CSS but no table tags, and generates fully valid XHTML output
* You need to specify a stylesheet like the one that you find in
* data/stylesheet.css to make this work.
* @package HTML_QuickForm_Renderer_Tableless
* @author Alexey Borzov <borz_off@cs.msu.su>
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @author Mark Wiesemann <wiesemann@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 0.4.2
* @link http://pear.php.net/package/HTML_QuickForm_Renderer_Tableless
var $_headerTemplate = "\n\t\t<legend>{header}</legend>\n\t\t<ol>";
* Element template string
"\n\t\t\t<li><label class=\"element\"><!-- BEGIN required --><span class=\"required\">*</span><!-- END required -->{label}</label><div class=\"element<!-- BEGIN error --> error<!-- END error -->\"><!-- BEGIN error --><span class=\"error\">{error}</span><br /><!-- END error -->{element}</div></li>";
"\n<form{attributes}>\n\t<div style=\"display: none;\">\n{hidden}\t</div>\n{content}\n</form>";
* Template used when opening a fieldset
var $_openFieldsetTemplate = "\n\t<fieldset{id}>";
* Template used when opening a hidden fieldset
* (i.e. a fieldset that is opened when there is no header element)
var $_openHiddenFieldsetTemplate = "\n\t<fieldset class=\"hidden\">\n\t\t<ol>";
* Template used when closing a fieldset
var $_closeFieldsetTemplate = "\n\t\t</ol>\n\t</fieldset>";
* Required Note template string
var $_requiredNoteTemplate =
"\n\t\t\t<li class=\"reqnote\"><label class=\"element\"> </label>{requiredNote}</li>";
* How many fieldsets are open
* Array of element names that indicate the end of a fieldset
* (a new one will be opened when a the next header element occurs)
var $_stopFieldsetElements = array ();
$this->HTML_QuickForm_Renderer_Default ();
* Called when visiting a header element
* @param object An HTML_QuickForm_header element being visited
$name = $header->getName ();
$id = empty ($name) ? '' : ' id="' . $name . '"';
if (!empty ($name) && isset ($this->_templates[$name])) {
$header_html = str_replace('{header}', $header->toHtml (), $this->_templates[$name]);
$header_html = str_replace('{header}', $header->toHtml (), $this->_headerTemplate);
if ($this->_fieldsetsOpen > 0 ) {
$this->_html .= $this->_closeFieldsetTemplate;
$openFieldsetTemplate = str_replace('{id}', $id, $this->_openFieldsetTemplate);
$this->_html .= $openFieldsetTemplate . $header_html;
} // end func renderHeader
* 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
// if the element name indicates the end of a fieldset, close the fieldset
if ( in_array($element->getName (), $this->_stopFieldsetElements)
&& $this->_fieldsetsOpen > 0
$this->_html .= $this->_closeFieldsetTemplate;
// if no fieldset was opened, we need to open a hidden one here to get
if ($this->_fieldsetsOpen === 0 ) {
$this->_html .= $this->_openHiddenFieldsetTemplate;
$html = $this->_prepareTemplate ($element->getName (), $element->getLabel (), $required, $error);
// the following lines (until the "elseif") were changed / added
// compared to the default renderer
$element_html = $element->toHtml ();
if (!is_null($element->getAttribute ('id'))) {
$id = $element->getAttribute ('id');
$id = $element->getName ();
$html = str_replace('<label', '<label for="' . $id . '"', $html);
'id="' . $id . '" name="' . $id,
$this->_html .= str_replace('{element}', $element_html, $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
if (!is_null($element->getAttribute ('id'))) {
$id = $element->getAttribute ('id');
$id = $element->getName ();
$html = $element->toHtml ();
'id="' . $id . '" name="' . $id,
$this->_hiddenHtml .= $html . "\n";
} // end func renderHidden
* 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);
if (!is_null($group->getAttribute ('id'))) {
$id = $group->getAttribute ('id');
$groupTemplate = $this->_groupTemplate;
$this->_html .= str_replace('{element}', $html, $groupTemplate);
} // end func finishGroup
* Called when visiting a form, before processing any form elements
* @param object An HTML_QuickForm object being visited
$this->_fieldsetsOpen = 0;
parent ::startForm ($form);
* 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 ) {
$requiredNote = $form->getRequiredNote ();
// replace default required note by DOM/XHTML optimized note
if ($requiredNote == '<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;"> denotes required field</span>') {
$requiredNote = '<span class="required">*</span> denotes required field';
$this->_html .= str_replace('{requiredNote}', $requiredNote, $this->_requiredNoteTemplate);
// close the open fieldset
if ($this->_fieldsetsOpen > 0 ) {
$this->_html .= $this->_closeFieldsetTemplate;
// 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);
$this->_html = str_replace('></label>', '> </label>', $this->_html);
// add a validation script
if ('' != ($script = $form->getValidationScript ())) {
$this->_html = $script . "\n" . $this->_html;
* Sets the template used when opening a fieldset
* @param string The HTML used when opening a fieldset
$this->_openFieldsetTemplate = $html;
} // end func setOpenFieldsetTemplate
* Sets the template used when opening a hidden fieldset
* (i.e. a fieldset that is opened when there is no header element)
* @param string The HTML used when opening a hidden fieldset
$this->_openHiddenFieldsetTemplate = $html;
} // end func setOpenHiddenFieldsetTemplate
* Sets the template used when closing a fieldset
* @param string The HTML used when closing a fieldset
$this->_closeFieldsetTemplate = $html;
} // end func setCloseFieldsetTemplate
* Adds one or more element names that indicate the end of a fieldset
* (a new one will be opened when a the next header element occurs)
* @param mixed Element name(s) (as array or string)
$this->_stopFieldsetElements = array_merge($this->_stopFieldsetElements,
$this->_stopFieldsetElements[] = $element;
} // end func addStopFieldsetElements
} // end class HTML_QuickForm_Renderer_Default
Documentation generated on Thu, 09 Nov 2006 16:30:05 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|