shazam Posted January 5, 2007 Share Posted January 5, 2007 Hello,I have been playing around with the PEAR HTML_QuickForm & DB_DataObject_FormBuilder packages.While I figured out how to extend the QuickForm Default renderer to meet my needs, I am having trouble figuring out how to do the same with FormBuilder.Here is an example of working code w/ QuickForm (hacked together from many examples on the web):[code]<link rel="stylesheet" type="text/css" href="/style/style.css"><?phprequire_once "HTML/QuickForm.php";require_once "HTML/QuickForm/Renderer/Default.php";class CSSRender extends HTML_QuickForm_Renderer_Default { var $_headerTemplate = "<tr class=form> <th class=form colspan=\"2\" scope=\"row\"> {header} </th> </tr>"; var $_elementTemplate = "<tr class=\"form\"> <td class=\"form\" id=\"label\"> {label} <!-- BEGIN required --> <span class=\"required\">*</span> <!-- END required --> </td> <td class=\"form\"> <!-- BEGIN error --> <span class=\"error\">{error}</span><br /> <!-- END error --> {element} </td> </tr>"; var $_formTemplate = "<form class=\"form\" {attributes}> {hidden} <table class=\"form\"> {content} </table> </form>"; var $_requiredNoteTemplate = "<tr> <td class=\"form\"></td> <td class=\"form\">{requiredNote}</td> </tr>"; }$form = new HTML_QuickForm('simple_test', 'get');$renderer = new CSSRender();$form->addElement('header', 'head', 'Contact Information','class=form');$form->addElement('text', 'name', 'Name','class=form');$form->addElement('text', 'phone', 'Phone','class=form');$buttons[] = &HTML_QuickForm::createElement('reset', 'btnClear', 'Clear');$buttons[] = &HTML_QuickForm::createElement('submit', 'btnSubmit', 'Submit');$form->addGroup($buttons, null, null, ' ');$form->addRule('name', 'Name required', 'required', '', 'client');$form->addRule('phone', 'Phone number required', 'required', '', 'client');if ($form->validate()) { # If the form validates then freeze the data $form->freeze();}$form->accept($renderer);echo $renderer->toHtml();?>[/code]Essentially, I can use the same Renderer w/ FormBuilder, but I cannot figure out how to convert the following QuickForm code to FormBuilder (the key being the 'class=form' option for addElement):[code]$form->addElement('header', 'head', 'Contact Information','class=form');$form->addElement('text', 'name', 'Name','class=form');$form->addElement('text', 'phone', 'Phone','class=form');[/code]FormBuilder, of course, auto-generates the form elements from database tables. I suppose I need to find a way to modify how FB creates the elements...Any ideas or examples on how to do this?Thanks!- B Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.