HTML:QuickForm: Setting default values in grouped elements
| From: | Bhinderwala, Shoeb | Date: | Tue, 19 Jul 2005 14:13:33 +0000 |
| Subject: | HTML:QuickForm: Setting default values in grouped elements | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-20056@lists.php.net to get a copy of this message | ||
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;
$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']);
The setValue() calls do not work.
-- Shoeb