Re: [SMARTY] loop within a <select multiple>
| From: | Jason Sweat | Date: | Sun, 23 Mar 2003 02:02:34 +0000 |
| Subject: | Re: [SMARTY] loop within a <select multiple> | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8841@lists.php.net to get a copy of this message | ||
From: "Jacques Jocelyn" <ml@salaireonline.com>
[loop for populating select options]
You should investigate the smarty html_options function
(http://smarty.php.net/manual/en/language.function.html.options.php)
in php make an assosiative array of code->value:
$sel_vals=array();
for($i=0,$j=count($fonction); $i<$j; $i++) {
$sel_vals[$fonction[$i]['code']] = $fonction[$i]['label'];
}
$smarty->assign('sel_vals', $sel_vals);
$smarty->assign('prev_sel', $simple_array_of_previous_selected_codes);
In the template:
<SELECT MULTIPLE NAME="fonction[]" SIZE="15">
{html_options options=$sel_vals selected=$prev_sel}
</select>