• Combining DHTMLRules, tableless layout and multiple page forms with HTML_QuickForm

    Posted on March 29th, 2007 Mark Wiesemann 10 comments

    With the new 0.3.0 release of HTML_QuickForm_DHTMLRulesTableless it is now possible to build forms with HTML_QuickForm that have the following features:

    • tableless layout (no <table> tags, very good accessibility)
    • DHTMLRules (form elements errors are shown on top of each element)
    • more than one page


    To achieve such forms, four PEAR package are needed:

    Information about building forms with HTML_QuickForm, about building multiple page forms with HTML_QuickForm_Controller, about using the tableless renderer, and about using the DHTMLRulesTableless class on forms built with HTML_QuickForms can be found in the PEAR manual. The only thing that I’ll explain here is the usage of DHTMLRulesTableless class with HTML_QuickForm_Controller.

    In general, a form page is added like in the following code snippet:

    
    class Page1 extends HTML_QuickForm_Page
    {
        // ...
    }
    $form =& new HTML_QuickForm_Controller();
    $page1 =& new Page1('page1');
    $form->addPage($page1);
    

    To use now the DHTMLRulesTableless class, you need to add and to change one line:

    
    require_once 'HTML/QuickForm/PageDHTMLRulesTableless.php';
    class Page1 extends HTML_QuickForm_PageDHTMLRulesTableless
    {
        // ...
    }
    $form =& new HTML_QuickForm_Controller();
    $page1 =& new Page1('page1');
    $form->addPage($page1);
    

    That means that you only need to do two things:

    • you need to include HTML/QuickForm/PageDHTMLRulesTableless.php
    • instead of extending from HTML_QuickForm_Page, your page classes need to extend from HTML_QuickForm_PageDHTMLRulesTableless

    The new HTML_QuickForm_PageDHTMLRulesTableless class is mostly a simple copy of the HTML_QuickForm_DHTMLRulesTableless class, but it extends HTML_QuickForm_Page and not HTML_QuickForm. This code duplication couldn’t be avoided because of a bad design of the Page class of HTML_QuickForm_Controller. After HTML_QuickForm2 is ready, a new Controller package is planned, and Alexey Borzov already announced that his new package will have a better design to avoid the need of such code duplications.

     

    10 Responses to “Combining DHTMLRules, tableless layout and multiple page forms with HTML_QuickForm”

    1. Don’t you have a example running?

    2. Mark Wiesemann

      Harold, no, there is currently no complete example available. Do you need any help on this topic? Then just reply here or send me an email.

      I have added an item to my TODO list about adding an example.

    3. I’m trying to set this up, exactly the way that you’re explaining here - but with QF 3.2.10, QF_Controller 1.0.8, DHTMLRulesTableless 0.3.3, and Renderer_Tableless, I get the original layout - NOT the tableless layout. I’m not getting any errors, mind you - it’s like it’s just passing it straight through. Unless there’s something I’m completely missing?

    4. Twyst, you need to define your own HTML_QuickForm_Action_Display class that takes care of using the tableless renderer. The usage of this renderer is described in the PEAR manual.

      Thanks for asking this; I’ll consider this point for the promised example code.

    5. Hi Mark,
      I faced the same problem as Twyst by following the PEAR manual stated in your reply.
      The following are the code I used to customized my QuickForm renderer.
      $form =& new HTML_QuickForm();
      $renderer =& new HTML_QuickForm_Renderer_Tableless();
      $form->accept($renderer);
      echo $renderer->toHtml();
      Did I miss out some setting. Thanks in advance for helping.

    6. [...] 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 [...]

    7. Johnny, I’ve written a short tutorial about the missing steps for the tableless layout online:
      Using the tableless renderer together with HTML_QuickForm_Controller

    8. Thanks alot Mark.
      I notice that I made a mistake by calling $form->toHtml(). Once I use $renderer->toHtml(), everything work perfectly.
      Thanks Mark for the prompt reply ;) Merry Christmas and Happy New Year 2008!

    9. Hi i just do a form in quickform,i want to be multi pages

      one page is easy,how can make one page to two page

      for example:
      step1
      name:
      email:

      and step2
      password:
      confirmed password:

      Thanks

    10. James, you’re either looking for HTML_QuickForm_Controller or you need to simulate the paging yourself (sessions are then your friends).

    Leave a Reply