Using HTML_QuickForm with Savant

PLEASE NOTE: I do not provide FREE support for any of the code below. If I am in a very good mood, I might help you, else I might ask for money from you to do work. I have rent and bills to pay - I've already been good enough to share my work here, so don't be surprised if I expect you to pay for support. If you want to know why I felt I needed to add this paragraph, please read http://pookey.co.uk/pear/rude.txt

2 Examples showing how Savant can be used with HTML_QuickForm with both a static, and dynamic template.

The 'static' example is a bit of a hack, I'm working on a better renderer (mostly finished, few bugs to iron out though). This page shows example output of various array based renderers.

Working example - static renderer

Static Template

Working example - dynamic renderer

Dynamic Template

Form Code

Renderer Code

HTML_Quickform_Controller and Savant

The same renderer can be used with HTML_QuickForm_Controller simply by creating a custom class extending HTML_QuickForm_Action_Display. This code below shows how to create a class that will use a default renderer for your form, or use a custom per-page one if a file exists.

class ActionDisplay extends HTML_QuickForm_Action_Display
{
    function _renderForm(&$page, $refId = null)
    {
        $renderer =& new HTML_QuickForm_Renderer_Savant();
        $page->accept($renderer);
 
        $tpl =& new Savant2();
        $tpl->addPath('template', MODULE_SIGNUP_ROOT . 'templates/');
        $tpl->assignRef('form', $renderer->toArray());
        $name = get_class($page);
        if (file_exists(MODULE_SIGNUP_ROOT . 'templates/' . $name . '.tpl.php'))
        {
          $tpl->display($name . '.tpl.php');
        }
        else
        {
          $tpl->display('main.tpl.php');
        }
 
    }
}