Re: Quickform group default values
| From: | Bertrand Mansion | Date: | Tue, 09 Dec 2003 08:30:20 +0000 |
| Subject: | Re: Quickform group default values | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-9398@lists.php.net to get a copy of this message | ||
<graeme@inetix.com.au> wrote :
>
>
> I've actually filed this as bug (http://pear.php.net/bugs/bug.php?id=351) but
> I'm hoping I can get some help in the interim with this as the problem is
> becoming more critical.
>
> I'm creating a groups of form elements that require default values filled in.
> I've used the same method described at
>
> http://marc.theaimsgroup.com/?l=pear-general&m=106554883600317&w=2
>
> I'm having the same issue subsequently described where one group fails to have
> the default form values filled in. Poking through the code I've confirmed
> that
> everything appears to be working correctly but I keep getting myself lost in
> the code.
>
> I've made some cut-down sample code available at
> http://inetix.com.au/test.php.html which illustrates the
> problem.
This is again the same array_merge() problem. This function is really crap
and has caused so much problems that I wonder why it's in php. Maybe just to
encourage developers to write their own better thought out replacement
method... Anyway, that's what we are going to do in the next release of
QuickForm, to avoid this kind of bugs.
The array_merge() function is not intelligent enough to make a difference
between an integer and a string when they are used as keys in you array. Or
is it php... So if it finds something that looks like an integer, it
renumbers your keys. Very clever, hey !
In the meanwhile, you can fix your problem by not using integers for your
field names :
$i=0;
foreach ($editdata as $row) {
$defaults['field'.$i] = array('user_name'=>$row['heading'],
'user_type'=>$row['type']
);
$i++;
}
(...)
for ($i=0; $i < $form_fields; $i++) {
$fields = array();
$fields[] =& HTML_QuickForm::createElement('text', 'user_name', NULL);
$fields[] =& HTML_QuickForm::createElement('select', 'user_type', NULL ,
$types);
$form->addGroup($fields, 'field'.$i, "Field $i");
}
HTH
Bertrand Mansion
Mamasam