Re: Quickform->setDefaults and Groups

From: Date: Tue, 04 Mar 2003 09:38:01 +0000
Subject: Re: Quickform->setDefaults and Groups
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-4036@lists.php.net to get a copy of this message
Bertrand Mansion wrote:
<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 Hi,
I'm just going to not use a group for this as it really isn't. I think the best solution for me is to just use: $form->addElement('text', 'ceo_title' ..... $form->addElement('text' 'ceo_fname'..... $form->addElement('text' 'ceo_lname'..... and then $form->setElementTemplate('somehtml', array('ceo_title Thus using a layout function for a layout problem. Can't wait to see QuickForm work properly with templates. I'm currently creating a huge online form (8 pages, some 100+ db fields) and although QuickForms is a great help it's getting rather messy with all the layout and code mixed together. Jeroen

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