Re: Quickform->setDefaults and Groups

From: Date: Mon, 03 Mar 2003 16:53:59 +0000
Subject: Re: Quickform->setDefaults and Groups
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-4030@lists.php.net to get a copy of this message
<jeroen@terena.nl> wrote : > Hi, > > Does anybody know how I can set the default values for a grouped > elements added to the form object with following code? > > $ceo['title'] = &HTML_QuickForm::createElement('text', > 'ceo_title'); > $ceo['fname'] = &HTML_QuickForm::createElement('text', > 'ceo_fname'); > $ceo['lname'] = &HTML_QuickForm::createElement('text', > 'ceo_lname'); > $form->addGroup($ceo, null, 'CEO', '&nbsp;'); > > I can do: > $DEFAULTS['ceo'] = array("ceo_title"=>'test', > "ceo_fname"=>'test', > "ceo_lname"=>'test'); > but that only works when I set the groupname to ceo and I explicitly > keep it null because otherwise my record in the DB does not get updated. > I don't want the grouped elements to become an HTML array, I just want > them to be grouped so I can easily use groupTemplates. Maybe that's not > what groups are meant for.. Hi Jeroen, At the moment, you can't use setDefaults if your group doesn't have a name because QuickForm looks in its elements list for a name and if it's null, then it won't find it. So, in the meanwhile, you can do it this way: $ceo['title'] = &HTML_QuickForm::createElement('text', 'ceo_title'); $ceo['fname'] = &HTML_QuickForm::createElement('text', 'ceo_fname'); $ceo['lname'] = &HTML_QuickForm::createElement('text', 'ceo_lname'); $group =& $form->addGroup($ceo, null, 'CEO', '&nbsp;'); $group->setValue(array("ceo_title"=>'Bertrand', "ceo_fname"=>'', "ceo_lname"=>'Mansion')); Problem is that these values are not defaults and will be set all the time, overriding submitted values, so you need to manually check that. That's not very clean... :( Apparently, we have a problem with the setDefaults() behaviour. I'll try to fix that this week. Anyway, groups should be thought more as logical or organisational entities, not as layout entities. When we will have templates, this will be easier to understand. Alexey Borzov is currently working on a renderer for QuickForm with an ITX implementation. When the API will be finalized, we will commit it and let other developers implement renderers for their template engines. Be patient :) Bertrand Mansion Mamasam

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