select_box(), multi_select(), multi_select_box() form()

A drop-down of value => text pairs; multi_select() / multi_select_box() allow several values (name[]).

form()->select_box($name, $values, $extra = [], $replace = [])
form()->multi_select($name, $values, $extra = [], $replace = [])
form()->multi_select_box($name, $values, $extra = [], $replace = [])

Options

OptionMeaning
$valuesValue => text; a value => [value => text] entry makes an <optgroup>.
selectedSelected value(s); default $replace[name].
show_textFirst empty option: 1 shows - Select -, a string shows that text.
translatePass the texts through t().
disabled, required, class, class_add, sizing, floatingAs for input().
edit_link, tip, inline_help, no_labelRow options of input().

Example

Code

$colors = ['red' => 'Red', 'green' => 'Green', 'blue' => 'Blue'];
$sizes = ['Clothes' => ['s' => 'S', 'm' => 'M', 'l' => 'L'], 'Shoes' => ['40' => '40', '41' => '41']];
return form(['color' => 'green', 'tags' => ['red' => 1, 'blue' => 1]])
    ->select_box('color', $colors, ['show_text' => 1])
    ->select_box('size', $sizes, ['desc' => 'Size (grouped)'])
    ->multi_select('tags', $colors, ['desc' => 'Colours'])
    ->multi_select_box('extra_colors', $colors, ['selected' => ['green' => 1]]);

Notes

  • A multi select posts name[]; read it as an array and check each value against the list.
  • Selected values of a multi select are the keys of an array (['red' => 1, 'blue' => 1]); a plain list ['red', 'blue'] selects nothing unless type is 1 (compare by text).
  • For search, tags and remote options see tom_select_box().

Bootstrap 3 and 5

Bootstrap 5 renders form-select; sizing sizes selects there always, under Bootstrap 3 only with CONF_SIZING_ON_SELECTS_ALL_FW.

See also: html/select_box, form/tom_select_box, form/radio_box