Skip to content

Commit

Permalink
form_select_multiple(): optional arg is list of selected values
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpanderson committed Mar 7, 2024
1 parent 7c6490a commit 9653f4a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions html/inc/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ function form_select($label, $name, $items, $selected=null) {
}

// same, for multiple select.
// flags, if non-null, is a boolean array saying which ones are selected
// $selected, if non-null, is a list of selected values
//
function form_select_multiple($label, $name, $items, $flags=null) {
function form_select_multiple($label, $name, $items, $selected=null) {
echo sprintf('
<div class="form-group">
<label align=right class="%s" for="%s">%s</label>
Expand All @@ -401,14 +401,12 @@ function form_select_multiple($label, $name, $items, $flags=null) {
',
FORM_LEFT_CLASS, $name, $label, FORM_RIGHT_CLASS, $name, $name
);
$n = 0;
foreach ($items as $i) {
echo sprintf(
'<option %s value=%s>%s</option>',
($flags && $flags[$n])?'selected':'',
($selected && in_array($i[0], $selected))?'selected':'',
$i[0], $i[1]
);
$n++;
}
echo "</select></div></div>\n";
}
Expand Down

0 comments on commit 9653f4a

Please sign in to comment.