select_box(), multi_select(), multi_select_box() html()
A bare <select> (no form row) from value => text pairs; multi_select() / multi_select_box() post name[].
html()->select_box($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $extra = [])
html()->multi_select($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $disabled = false)
html()->multi_select_box($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $disabled = false)Опції
| Опція | Значення |
|---|---|
$name, $values, $selected | Name; value => text (a value => array makes an optgroup); selected value (multi: keys of an array). |
$show_text | 1: a - Select - first option; a string: that text. |
$type | 2 (default) compares the selected value with the keys, 1 with the texts. |
$add_str, $translate | Extra attributes string; translate the texts. |
extra / array form | All of it as one array: select_box(['name' => ..., 'values' => ..., 'selected' => ..., 'class_add', 'disabled', 'required', 'force_id']). |
Приклад
Код
$values = ['k1' => 'key1', 'k2' => 'key2', 'k3' => 'key3'];
return html()->select_box('size', $values, 'k2', 1)
. ' ' . html()->multi_select('tags', $values, ['k1' => 1, 'k3' => 1])
. ' ' . html()->multi_select_box(['name' => 'colors', 'values' => $values, 'class_add' => 'input-medium']);Примітки
- For a labelled form row use form()->select_box(); these return the control alone.
Bootstrap 3 and 5
form-control under Bootstrap 3, form-select under 5.
Див. також: form/select_box, html/select2_box, html/tom_select_box