The word 'dynamic' in renderer name means that exact form layout is defined at script runtime. This also means that you can create one template file for all your forms. That template should contain a block for every distinct element 'look' appearing in your forms and also some special blocks. If a special block is not set for an element, the renderer falls back to a default one.
If most of your forms tend to share the same look (a good example would be back-office interface), your best bet will be to use Dynamic renderer. If each of your forms has a really special layout, you should go with a Static one.
This is a somewhat minimal template, but it contains all the necessary elements to render any form you are able to define with the package.
qf_main_loop
This block should always be present and should be a parent for all visible elements' blocks. It is used to implement "flow", to render elements one after another.
qf_element
This is the default block for rendering form elements. This block should always be present, as the renderer uses the following logic to decide which block to use for an element's output:
If a special block was set for an element, use that
If a block qf_%element's type%
(e.g. qf_password
) exists, use that
Use qf_element
qf_element_required
The block will be touch'd if an element is required.
qf_element_error
An error associated with an element will be output here.
qf_header
This is the default block used to output headers. Should be present unless you have no headers in your form.
qf_group
Default block to output groups. Should be present unless you do not use grouped elements.
qf_group_loop
An analog of qf_main_loop
, used to render group's elements
one after another. A %group's block%_loop
should
always be present inside %group's block%
qf_group_element
A default block to render group's elements, %group's block%_element
should always be present inside %group's block%_loop
(for the
same reason as the qf_element
should be present in
qf_main_loop
)
qf_error_loop
This is used to output collected errors for the elements that do not have a
%element's block%_error
block.
qf_hidden_loop
<input type="hidden" /> elements are rendered here.
{qf_javascript}
Javascript for client-side form validation will be output here.
{qf_required_note}
If there are required elements in the form, a note will be output here
Assuming the template is in ./qform.html
:
<?php
require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
require_once 'HTML/Template/Sigma.php';
// Instantiate the template object and load the template file
$tpl =& new HTML_Template_Sigma('.');
$tpl->loadTemplateFile('qform.html');
// Instantiate the renderer and process the form
$renderer =& new HTML_QuickForm_Renderer_ITDynamic($tpl);
$form->accept($renderer);
// Output the results
$tpl->show();
?>
Note that we do not show how the form is built here, that's because the example will work for virtually any form.
Template class compatibilityThis renderer was developed and tested using HTML_Template_Sigma. While it probably will work with HTML_Template_IT, no warranties can be given.
Removing empty blocksThe renderer assumes that the template object was set up to remove empty blocks (this is the default behaviour). If that is not true, the results will be pretty discouraging.