Proposal for "HTML_QuickForm_Renderer_Tableless"

» Metadata » Status
» Description
Tableless renderer for HTML_QuickForm

The default renderer of HTML_QuickForm uses tables. For new a website I needed fully tableless code, and therefore, I wrote this new renderer.

Changes since version 0.1.1:

  1. re-started with totally new code (thanks to Jan Wagner for providing some code snippets)
  2. layout now supports also groups of elements
  3. layout now uses fieldset (for the whole form) and legend (for the header element)
  4. labels have now "for"-attribute and elements have an "id"-attribute, which makes it possible to click on a label to set the focus to a text field or to check a radio button or a checkbox
  5. added groups of radio buttons and checkboxes to the examples
  6. updated PHP and PEAR dependencies


Changes since version 0.2.0:

  1. added multiple fieldsets:
    * every header element in a form indicates now the start of a new fieldset
    * the value of such an header element is used as the legend tag
    * if the first visible element is not a header element, a fieldset will be generated without a legend tag
  2. example 1 shows now three fieldset
  3. example 2 shows now four fieldset, the firstset contains no legend (see above)


Changes since version 0.2.1:

  1. corrected position of last closing fieldset tag (was outside the form tag)
  2. added setOpenFieldsetTemplate() and setCloseFieldsetTemplate() methods
  3. removed second example (it is now included in HTML_QuickForm_DHTMLRulesTableless)


Changes since version 0.2.2:

  1. removed 99% copied _prepareTemplate() method as QuickForm bug #7820 was closed
  2. updated dependency therefore to HTML_QuickForm >= 3.2.6
  3. replaced header comment blocks with the new format


Changes since version 0.2.3:

  1. fix: headers without text don't generate a legend tag anymore
  2. changed behaviour: if the first visible element is not a header element, a fieldset is not generated anymore (it would not have a legend tag)
  3. new addStopFieldsetElements() method that accepts one or more element name(s) that indicate the end of a fieldset (this is shown in the online examples for the submit button)
  4. the required note is now always outside the last fieldset (for logical reasons: this note belongs to the whole form, not only to a single fieldset)
  5. removed additional div tag for groups (it wasn't necessary)
  6. added a new div tag (with class 'qfrow') for label and element (or group of elements) to ease customisation of layout
  7. optimized stylesheet (alignment of elements outside of fieldsets, removed unnecessary styles, fixed width of fieldset in IE)
  8. reduced usage code by one line (this adds the ability to use $form->toHtml() or $form->display())


Usage:

<?php
require_once 'HTML/QuickForm/Renderer/Tableless.php';
$renderer =& new HTML_QuickForm_Renderer_Tableless();
$GLOBALS['_HTML_QuickForm_default_renderer'] =& $renderer;
// usual code, e.g. new form fields, rules, ...
$form->display();
?>


It is also possible to use it like this:

<?php
require_once 'HTML/QuickForm/Renderer/Tableless.php';
// usual code, e.g. new form fields, rules, ...
$renderer =& new HTML_QuickForm_Renderer_Tableless();
$form->accept($renderer);
echo $renderer->toHtml();
?>


One also has to define a short stylesheet to make this work. The stylesheet can be customized for your needs, of course.

Example 1 (Source): A simple contact form using the Tableless renderer.
http://www.markwiesemann.de/php/Tableless/contact.php

Example 2 (Source): A simple contact form using the Tableless renderer and the DHTMLRules (see my proposal HTML_QuickForm_DHTMLRulesTableless for more information).
http://www.markwiesemann.de/php/DHTMLRules/contact_dhtmlrules.php
» Dependencies » Links
  • HTML_QuickForm >= 3.2.6
» Timeline » Changelog
  • First Draft: 2006-06-15
  • Proposal: 2006-06-15
  • Call for Votes: 2006-07-03
  • Mark Wiesemann
    [2006-06-17 12:26 UTC]

    Changes since version 0.2.0:
    - added multiple fieldsets:
    * every header element in a form indicates now the start of a new fieldset
    * the value of such an header element is used as the legend tag
    * if the first visible element is not a header element, a fieldset will be
    generated without a legend tag
    - example 1 shows now three fieldset
    - example 2 shows now four fieldset, the firstset contains no legend (see above)
  • Mark Wiesemann
    [2006-06-18 17:06 UTC]

    - corrected position of last closing fieldset tag (was outside the form tag)
    - added setOpenFieldsetTemplate() and setCloseFieldsetTemplate() methods
    - removed second example (it is now included in HTML_QuickForm_DHTMLRulesTableless)
  • Mark Wiesemann
    [2006-06-20 20:39 UTC]

    - removed 99% copied _prepareTemplate() method as QuickForm bug #7820 was closed
    - updated dependency therefore to HTML_QuickForm >= 3.2.6
    - replaced header comment blocks with the new format
  • Mark Wiesemann
    [2006-06-25 14:23 UTC]

    - fix: headers without text don't generate a legend tag anymore
    - changed behaviour: if the first visible element is not a header element, a fieldset is not generated anymore (it would not have a legend tag)
    - new addStopFieldsetElements() method that accepts one or more element name(s) that indicate the end of a fieldset (this is shown in the online examples for the submit button)
    - the required note is now always outside the last fieldset (for logical reasons: this note belongs to the whole form, not only to a single fieldset)
    - removed additional div tag for groups (it wasn't necessary)
    - added a new div tag (with class 'qfrow') for label and element (or group of elements) to ease customisation of layout
    - optimized stylesheet (alignment of elements outside of fieldsets, removed unnecessary styles, fixed width of fieldset in IE)
    - reduced usage code by one line (this adds the ability to use $form->toHtml() or $form->display())