我有这个下拉菜单,用户可以选择多个选项,如果表单出现错误,我如何在提交按钮后将选定的值保留在表单上
<th align="right" style="width: 264px"><label id="lcell">*Preferred City for Relocation Work :</label></th>
<td><select onchange="document.getElementById('cand_pref').style.display='none';" name="pcity[]" id="pcity" multiple="multiple" >
<?php
$pcitylist = array(
'Mizoram' => array('Aizawl', 'Champhai', 'Kolasib', 'Lawngtlai', 'Lunglei', 'Mamit', 'Saiha', 'Serchhip'),
'Nagaland' => array('Dimapur', 'Kohima', 'Mokokchung', 'Mon', 'Phek', 'Tuensang', 'Wokha', 'Zunheboto'),
'Orissa' => array('Angul', 'Boudh', 'Bhadrak', 'Bolangir', 'Bargarh', 'Baleswar', 'Cuttack', 'Debagarh', 'Dhenkanal', 'Ganjam', 'Gajapati', 'Jharsuguda', 'Jajapur', 'Jagatsinghpur', 'Khordha', 'Kendujhar', 'Kalahandi', 'Kandhamal', 'Koraput', 'Kendrapara', 'Malkangiri', 'Mayurbhanj', 'Nabarangpur', 'Nuapada', 'Nayagarh', 'Puri', 'Rayagada', 'Sambalpur', 'Subarnapur', 'Sundargarh'),
'Puducherry' => array('Karaikal', 'Mahe', 'Puducherry', 'Yanam')
);
foreach ($pcitylist as $key => $pcitylist1) {
echo '<optgroup label="'.$key.'">';
foreach ($pcitylist1 as $finalCity) {
echo '<option value="' . $finalCity . '"' . (isset($_POST['pcity']) && $_POST['pcity'] == $finalCity ? ' selected' : '') . '>' . $finalCity . '</option>';
}
echo '</optgroup>';
}
?>
</select></td>