Contents |
VF_SelectGroup→addField
VF_SelectGroup→addField — Adds a new option to the current select list
Description
addField (string $value, string $label[, bool $selected]);
Adds a new option to the current select list.
Parameters
- value
The value of the option element - label
The label for the option element - selected
If true, the current option field is selected by default. Default value: false.
Return values
Returns a new VF_SelectOption object.
Examples
//*** This is what we had so far.
$objSelectList = $objForm->addField("support-type", "Support type", VFORM_SELECT_LIST,
array(
"required" => true
),
array(
"required" => "You must select a support type."
),
array(
"tip" => "If you're not sure, just choose 'no support'."
)
);
//*** This is where the magic happens.
// The default value needs to be empty in order to do a 'required' check.
$objSelectList->addField("Select support type", "", true);
// In HTML this looks like: <option value="tech">Tech support</option>
$objSelectList->addField("Tech support", "tech");
//*** This is where we insert a new select group object
$objNewGroup = $objSelectList->addGroup("Some other options");
$objNewGroup->addField("Friendly support", "friendly");
$objNewGroup->addField("No support", "no-support");

