Re: HTML:QuickForm: Setting default values in grouped elements
| From: | Justin Patrin | Date: | Tue, 19 Jul 2005 16:33:32 +0000 |
| Subject: | Re: HTML:QuickForm: Setting default values in grouped elements | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20061@lists.php.net to get a copy of this message | ||
On 7/19/05, Bhinderwala, Shoeb <SBhinderwala@wellington.com> wrote:
> Along with other elements on my HTML QuickForm for member registration,
> I have a group of elements to display phone number area code, exchange
> and last 4 digits.
>
> I am loading a member record from the database and populate the form
> with default values from the database. However, I am not sure how to
> populate the group of elements that display the phone number details.
>
> Here is the code that creates the group:
>
> $phone_areacode_elem = &HTML_QuickForm::createElement('text',
> 'phone_areacode', null, array('size' => 3, 'maxlength' =>
> 3));
> $phone_exchange_elem =
> &HTML_QuickForm::createElement('text','phone_exchange', null,
> array('size' => 3, 'maxlength' => 3));
> $phone_last4_elem =
> &HTML_QuickForm::createElement('text','phone_last4',
> null, array('size' => 4, 'maxlength' => 4));
> $phone[] = $phone_areacode_elem;
> $phone[] = $phone_exchange_elem;
> $phone[] = $phone_last4_elem;
setValue isn't working below because you're making copies of the
elements in the $phone array. Use =& here as well. However....
> $form->addGroup($phone, 'phone', 'Phone: ', '-');
>
> Here is the code to set default values in the form:
>
> //get default values from database
> $member_rec = get_member_record($_SESSION['email']);
> $form->setDefaults($member_rec);
>
> //set default values for elements in the phone group
> $phone_areacode_elem->setValue($member_rec['phone_areacode']);
> $phone_exchange_elem->setValue($member_rec['phone_exchange']);
> $phone_last4_elem->setValue($member_rec['phone_last4']);
>
setValue really isn't the correct call if your'e setting defaults. You
should be using $form->setDefaults().
--
Justin Patrin