Using the tableless renderer together with HTML_QuickForm_Controller

My post “Combining DHTMLRules, tableless layout and multiple page forms with HTML_QuickForm” led to several inqueries about why the layout with the shown code snippets still uses tables. The answer is: One needs to tell HTML_QuickForm_Controller (QFC) about the usage of another renderer.

To achieve this, three basic steps are needed:

Step 1: Include the code of the tableless renderer.

require_once 'HTML/QuickForm/Renderer/Tableless.php';

Step 2: Create a new class that extends from the HTML_QuickForm_Action_Display class, and overload the _renderForm() method. This method basically does the same as the code examples for the single page forms do. The only difference is the usage of $page instead of $form (a page in QFC extends the HTML_QuickForm class).

class Tableless_Display extends HTML_QuickForm_Action_Display
    function _renderForm(&$page)
        $renderer =& new HTML_QuickForm_Renderer_Tableless();
        echo $renderer->toHtml();

Step 3: Tell QFC to use the new class instead of the default HTML_QuickForm_Action_Display class for displaying the form. ($wizard is a HTML_QuickForm_Controller instance in this example.)

$wizard->addAction('display', new Tableless_Display());

After these three steps, you should have a tableless layout together with DHTML rules.

Comments are closed.