Represents <select>
element that provides a menu of options. Documentation:
Form model:
final class ProfileForm extends FormModel
{
public ?string $color = 'f00';
public function getAttributeLabels(): array
{
return [
'color' => 'Select color',
];
}
}
Widget:
echo Select::widget()
->formAttribute($profileForm, 'color')
->optionsData([
'f00' => 'Red',
'0f0' => 'Green',
'00f' => 'Blue',
]);
Result will be:
<div>
<label for="profileform-color">Select color</label>
<select id="profileform-color" name="ProfileForm[color]">
<option value="f00">Red</option>
<option value="0f0">Green</option>
<option value="00f">Blue</option>
</select>
</div>
string
- number or numeric string (see is_numeric())
bool
null
- any stringable values
Multiple select requires iterable or null
value.