print a select menu
function input_select($element_name, $selected, $options, $multiple = false) {
print '<select name="' . $element_name;
if ($multiple) { print '[]" multiple="multiple'; }
print '">';
$selected_options = array();
if ($multiple) {
foreach ($selected[$element_name] as $val) {
$selected_options[$val] = true;
}
} else {
$selected_options[ $selected[$element_name] ] = true;
}
foreach ($options as $option => $label) {
print '<option value="' . htmlentities($option) . '"';
if ($selected_options[$option]) {
print ' selected="selected"';
}
print '>' . htmlentities($label) . '</option>';
}
print '</select>';
}
Related examples in the same category