summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_html.class8
1 files changed, 5 insertions, 3 deletions
diff --git a/it_html.class b/it_html.class
index e4d7245..56918e1 100644
--- a/it_html.class
+++ b/it_html.class
@@ -313,7 +313,7 @@ function img($args)
* @param $options array (value => text) of available options or
* string key:val{,key:val} where key will be rawurldecoded so it may contain %2C as comma
* supports optgroups as array (value => optgroup => array(value => text))
- * @param $selected optional currently selected value
+ * @param $selected optional currently selected value, or comma-separated list or array for multi-select
*/
function select($tags, $options, $selected = null)
{
@@ -330,6 +330,8 @@ function select($tags, $options, $selected = null)
}
}
+ $selected = (isset($selected) && !is_array($selected)) ? explode(',', $selected) : (array)$selected;
+
$html = "";
foreach($options as $value => $option)
{
@@ -337,11 +339,11 @@ function select($tags, $options, $selected = null)
{
$grouphtml = "";
foreach($option as $optval => $opt)
- $grouphtml .= $this->_tag("option", array(array('value' => $optval, 'selected' => isset($selected) ? $optval == $selected : false), Q($opt)));
+ $grouphtml .= $this->_tag("option", array(array('value' => $optval, 'selected' => in_array($optval, $selected)), Q($opt)));
$html .= $this->_tag("optgroup", array(array('label' => $value, $grouphtml)));
}
else
- $html .= $this->_tag("option", array(array('value' => $value, 'selected' => isset($selected) ? $value == $selected : false, 'disabled' => $option === ""), (trim($option) === "") ? " " : Q($option)));
+ $html .= $this->_tag("option", array(array('value' => $value, 'selected' => in_array($value, $selected), 'disabled' => $option === ""), (trim($option) === "") ? " " : Q($option)));
}
return $this->_tag("select", array($tags, $html));