You may often want to output form elements manually, especially if the form has a complex layout:
<complex html><?= $form->getElementById('someElement'); ?><more complex html>
or, if using a template engine
<complex html>{{ form.getElementById('someElement') }}<more complex html>
However, you will require a rendering step if your form uses client-side validation or contains Javascript-backed elements like Hierselect. Stub renderer can be used in such circumstances to reduce overhead as the results of a more complex renderer like Default will be discarded.
Stub renderer serves as a container for JavascriptBuilder object and does some minimal form
processing: it can group errors and hidden elements if group_errors
and
group_hiddens
parameters are set to true. The accumulated data is available
through getErrors() and
getHidden() methods,
respectively. You can also use hasRequired() method to
check whether form contains required elements.
Using Stub Renderer
<?php
$renderer = $form->render(
HTML_QuickForm2_Renderer::factory('stub')
->setOption('group_errors', true);
);
// outputting JS libraries
foreach ($renderer->getJavascriptBuilder()->getLibraries() as $link) {
echo $link . "\n";
}
// outputting form errors
foreach ($renderer->getErrors() as $id => $error) {
echo "<a href=\"#{$id}\">{$error}</a><br />";
}
// ...
// form output code goes here
// ...
echo $renderer->getJavascriptBuilder()->getFormJavascript();
?>