Contents |
VF_SelectOption→__construct
VF_SelectOption→__construct — Adds a new option to the current select list
This class is for internal use only. See the example at the bottom of this page for best practices on how to insert an option element to a select list.
Description
__construct (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 example is copied directly from the Advanced contact form tutorial
//*** 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");
$objSelectList->addField("Friendly support", "friendly");
$objSelectList->addField("No support", "no-support");

