check_box(), switch_box(), multi_check_box() form()

A single check box (switch_box(): a Bootstrap 5 switch) or a group of check boxes posting name[] (multi_check_box()).

form()->check_box($name, $value = '', $extra = [], $replace = [])
form()->switch_box($name, $value = '', $extra = [], $replace = [])
form()->multi_check_box($name, $values, $extra = [], $replace = [])

Options

OptionMeaning
$value / $valuesValue posted when checked (default 1); for multi_check_box() value => label.
selectedChecked value(s); default $replace[name].
desc, no_labelLabel of the row; no_label puts the text next to the box only.
btn_groupDraw the boxes as toggle buttons (CONF_BOXES_USE_BTN_GROUP is the default).
horizontalmulti_check_box(): in one line (default) or one per line.
name_as_arraymulti_check_box(): post name[value]; without it each box posts name_value.
switchWhat switch_box() sets.

Example

Code

return form(['agree' => 1, 'notify' => 1, 'days' => ['mon' => 1, 'fri' => 1]])
    ->check_box('agree', ['desc' => 'I accept the terms', 'no_label' => 1])
    ->switch_box('notify', ['desc' => 'Email me about orders'])
    ->multi_check_box('days', ['mon' => 'Mon', 'tue' => 'Tue', 'wed' => 'Wed', 'thu' => 'Thu', 'fri' => 'Fri'], ['desc' => 'Delivery days', 'name_as_array' => 1]);

Notes

  • An unchecked box posts nothing: treat a missing key as 0.
  • The checked values of multi_check_box() are the keys of an array (['mon' => 1]), as $replace holds them after a post with name_as_array.

Bootstrap 3 and 5

switch_box() is a form-check form-switch under Bootstrap 5 and a plain check box under 3; with btn_group Bootstrap 5 uses btn-check inputs with btn labels.

See also: form/radio_box, form/active_box, html/check_box