Re: DB_Table QuickForm rules

From: Date: Thu, 20 Apr 2006 21:07:10 +0000
Subject: Re: DB_Table QuickForm rules
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23779@lists.php.net to get a copy of this message
On 4/20/06, Charlie van de Kerkhof <pear@mowd.nl> wrote: > Hi, > > I'm trying to get the form rules through DB_Table working. > > I have setup the column definition: > >>> > class Bet extends DB_Table > { > [...] > 'title' => array( > 'type' => 'varchar', > 'size' => 255, > 'require' => true, > 'qf_label' => 'Bet:', > 'qf_type' => 'text', > 'qf_attrs' => array('size' => 50), > 'qf_rules' => array( > 'required' => 'This field is required.' > ) > > ), > } > <<< > And in my script to build the form I have this: > >>> > $oBet =& new Bet($G_DB, 'bet', 'safe'); > $G_FORM = new HTML_QuickForm('lab', 'post', '', '', > ''); > > // use renderer > require_once ('HTML/Template/Sigma.php'); > require_once 'HTML/QuickForm/Renderer/ITStatic.php'; > $G_TPL->loadTemplateFile('tpl/'.SCRIPT_NAME_WO.'_form.tpl'); > $renderer =& new HTML_QuickForm_Renderer_ITStatic($G_TPL); > $renderer->setRequiredTemplate('{label}<span class="required">*</ > span>'); > $renderer->setErrorTemplate(''); > > // make form > $element =& $oBet->getFormElement('title', 'vbet'); > $G_FORM->addElement($element); > if ($G_FORM->validate()) > { > $G_FORM->process('processBet'); > } > $G_FORM->accept($renderer); > $G_TPL->show(); > >>> > > Now the 'title' is set to be required, but if I submit my form with > an empty title (vbet) it is processed as is. No error will display. > Is it my implementation of the renderer? > The problem here is that you're using your own form. If you add an element to your own form you have to add the rules as well. Rules are *not* part of the element, they're added on their own. Your real problem is not that there is little documentation, your problem is that you don't understand what you're trying to use here. If you follow the normal example for DB_Table I'm sure the rules work just fine. However, you're using its getFormElement method and adding this to your own form. To use HTML_QuickForm manually (as you are) you really need to understand how *it* works. Now...you should very easily be able to us eyour own renderer with the form you get from DB_Table. The problem is likely that you aren't doing it right because you don't understand the underlying packages. Use the getForm() call. If it doesn't work there's something wrong with how you're doing things. Try using print_r() on the various objects, trace the code, etc. And, just FYI, there is another package which does QF forms from a DB. DB_DataObject_FormBuilder. Of course I've never used anything but the default renderer with it. -- Justin Patrin

« previous php.pear.general (#23779) next »