Stub Renderer

Stub Renderer – Minimum overhead renderer to use when actual form output is done manually

Purpose of Stub Renderer

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();
?>
Represents the form as an array (Previous) Client-side validation and Javascript-backed elements (Next)
Last updated: Tue, 29 Jul 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: lmartelli
There's an extra ';' in the exemple after setOption(). It should read:

$renderer = $form->render(
HTML_QuickForm2_Renderer::factory('stub')
->setOption('group_errors', true)
);