SOURCE CODE: Modification to the html_options function: <select multiple> enabled
| From: | Bertrand DUNOGIER | Date: | Tue, 05 Jun 2001 22:52:52 +0000 |
| Subject: | SOURCE CODE: Modification to the html_options function: <select multiple> enabled | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-871@lists.php.net to get a copy of this message | ||
Oooops, i sent the mail without the source code :)
Here is it.
/*======================================================================*\
Function: smarty_func_html_options
Purpose: Prints the list of <option> tags generated from
the passed parameters
\*======================================================================*/
function smarty_func_html_options()
{
$print_result = true;
extract(func_get_arg(0));
$html_result = "";
foreach($selected as $key => $val)
echo "$key => $val<br>";
settype($selected, 'array');
if (isset($options)) {
settype($options, 'array');
foreach ($options as $key => $value) {
$html_result .= "<option value=\"$key\"";
if ($multiple == true) {
if ($selected[$key])
$html_result .= " selected";
}
else {
if (in_array($key, $selected))
$html_result .= " selected";
}
$html_result .= ">$value</option>\n";
}
} else {
settype($output, 'array');
settype($values, 'array');
for ($i = 0; $i < count($output); $i++) {
/* By default, check value against $selected */
$sel_check = $values[$i];
$html_result .= "<option";
if ($i < count($values))
$html_result .= " value=\"".$values[$i]."\"";
else
$sel_check = $output[$i]; /* if more outputs than values, then
check output against $selected */
if (in_array($sel_check, $selected))
$html_result .= " selected";
$html_result .= ">".$output[$i]."</option>\n";
}
}
if ($print_result)
print $html_result;
else
return $html_result;
}