select_box() table()

A drop-down in each row, posting field[value].

table()->select_box($name, $extra = [])

Options

OptionMeaning
valuesValue => text of the options.
selectedSelected value.
namePosted name; default the field name, [value] appended unless it holds a [.
(html options)Every option of html()->select_box().

Example

Name Status
Desk lamp
Office chair

Code

$rows = [
    1 => ['id' => 1, 'name' => 'Desk lamp', 'status' => 'new'],
    2 => ['id' => 2, 'name' => 'Office chair', 'status' => 'sent'],
];
$statuses = ['new' => 'New', 'paid' => 'Paid', 'sent' => 'Sent'];
return table($rows, ['no_pages' => 1])
    ->text('name')
    ->select_box('id', ['values' => $statuses, 'selected' => 'paid', 'name' => 'status', 'desc' => 'Status']);

Notes

  • The field value of the row is the key of the posted name (here status[1]); selected is the same for every row. For a per-row selection render the select in a func() column.
  • Ids are selectbox_<value>. It calls form().

See also: html/select_box, demo:table/form