Re: Quickform group default values
| From: | Graeme Merrall | Date: | Wed, 10 Dec 2003 05:02:27 +0000 |
| Subject: | Re: Quickform group default values | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-9443@lists.php.net to get a copy of this message | ||
Quoting Bertrand Mansion <bmansion@mamasam.com>:
> 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");
>
> }
>
That got it sorted. Thanks for your help.
Cheers,
Graeme