Introduction - renderers

Introduction - renderers – How to output the form

What are renderers?

Before release 3.0, form outputting logic was implemented as methods of HTML_QuickForm class. This led to two problems:

  1. Bloat of the said class (80+ methods!)

  2. Difficulties in adding new output logic (i.e. using template engines)

In release 3.0, new system was implemented. The form output logic is now contained in classes that extend HTML_QuickForm_Renderer, their behaviour is based on Visitor design pattern from the classic "Design Patterns" book. This gives the following advantages:

  1. Code for some particular output method is loaded only when the method is used.

  2. It is much easier to add new output method.

There are 8 renderers available since release 3.1.1, of which 2 are based on pre-3.0 code and 6 are new. The following template engines are directly suported: Smarty, HTML_Template_Sigma, HTML_Template_IT, HTML_Template_Flexy.

The main steps of using any available renderer are quite similar:

<?php
// include the renderer class
require_once 'HTML/QuickForm/Renderer/FooBar.php';
// instantiate the renderer
$renderer =& new HTML_QuickForm_Renderer_FooBar($options);
// do some customization
$renderer->adjustSomething('element1''...');
// ...
$renderer->adjustSomething('elementN''...');
// process the form
$form->accept($renderer);
// output the results
$renderer->toFooBar();
?>

Actual methods for customization and doing the output will of course depend on renderer type.

Concerning usage examples

Usage examples provided in the manual are pretty basic. More complex examples for Default renderer can be found in docs/ directory, for all other renderers - in docs/renderers/ directory of HTML_QuickForm.