为什么set_select
制作所有选项selected
?
$orgOptions = '';
if(!empty($organizations)){
foreach($organizations as $org){
$orgOptions .= '<option value="'.$org['id'].'" %sel-org>'.$org['name'].'</option>';
}
}
$depFormTemplate ='select name="department[%k][organization]" id="org-%k" class="dropdown">
<option value="">Organization Name</option>
'.$orgOptions.'
</select>';
if($this->input->post('department')){
foreach($this->input->post('department') as $key => $dep){
$search = array('%k', '%department', '%sel-org');
$replace = array(
$key,
set_value('department['.$key.'][department]'),
set_select('department['.$key.'][organization]',$dep['organization'])
);
echo str_replace($search, $replace, $depFormTemplate);
}
}