4 * -------------------------------------------------------------
7 * Purpose: prints out the options for an html_select item
8 * Credit: Taken from the original Smarty
9 * http://smarty.php.net
10 * -------------------------------------------------------------
12 function tpl_function_html_options($params, &$tpl)
14 require_once("shared.escape_chars.php");
20 foreach($params as $_key => $_val)
25 $
$_key = (string)$_val;
28 $
$_key = (array)$_val;
32 $
$_key = array_values((array)$_val);
35 $
$_key = array_values((array)$_val);
40 $extra .= ' ' . $_key . '="' . tpl_escape_chars($_val) . '"';
44 throw new Template_Exception("html_select: attribute '$_key' cannot be an array", $tpl);
51 if (is_array($options))
53 foreach ($options as $_key=>$_val)
55 $_html_result .= tpl_function_html_options_optoutput($tpl, $_key, $_val, $selected);
60 foreach ((array)$values as $_i=>$_key)
62 $_val = isset($output[$_i]) ?
$output[$_i] : '';
63 $_html_result .= tpl_function_html_options_optoutput($tpl, $_key, $_val, $selected);
69 $_html_result = '<select name="' . tpl_escape_chars($name) . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
75 function tpl_function_html_options_optoutput(&$tpl, $key, $value, $selected)
79 $_html_result = '<option label="' . tpl_escape_chars($value) . '" value="' . tpl_escape_chars($key) . '"';
80 if (in_array($key, $selected))
82 $_html_result .= ' selected="selected"';
84 $_html_result .= '>' . tpl_escape_chars($value) . '</option>' . "\n";
88 $_html_result = tpl_function_html_options_optgroup($tpl, $key, $value, $selected);
93 function tpl_function_html_options_optgroup(&$tpl, $key, $values, $selected)
95 $optgroup_html = '<optgroup label="' . tpl_escape_chars($key) . '">' . "\n";
96 foreach ($values as $key => $value)
98 $optgroup_html .= tpl_function_html_options_optoutput($tpl, $key, $value, $selected);
100 $optgroup_html .= "</optgroup>\n";
101 return $optgroup_html;