我是一个相当新的PHP,我一直无法使用该表格保存内存为radioboxes,checkboxes& (下拉列表)选择列表,因此我提交或选择的数据在提交时仍然存在。
<select name = "province[]" multiple size = "12">
<?php foreach ($PROVINCES as $key => $value) {?>
<option value = "<?php echo $value ?>"<?php (in_array('$key',$_POST['province'] ) )?'selected':'';?>><?php echo $value ?></option>
<?php }?>
</select>
<br><br>
<label for = "status">Status(Mult Select)<font color = "red">*</font></label>
<input type = "checkbox" name = "status[]" id = "Approved" value= "Approved"> Approved
<input type = "checkbox" name = "status[]" id = "Pending Application" value="Pending Application"> Pending Application
<input type = "checkbox" name = "status[]" id = "Active Service" value="Active Service"> Active Service
<br><br>
<label for = "location">Location<font color = "red">*</font></label>
<input type = "radio" name = "location" id = "Garage" value = "Garage"> Garage
<input type = "radio" name = "location" id= "Attic" value = "Attic"> Attic
<input type = "radio" name = "location" id = "House" value = "House"> House
</fieldset>
&#13;
答案 0 :(得分:1)
我的建议是使用PHP in_array函数来回显已检查的状态。 此外,总是很好地查看POST参数的状态(有助于确定浏览器发送到服务器的内容)
<pre><?php var_dump($_POST); ?></pre>
<input <?php if(in_array('Approved', $_POST['status'])) echo ' checked="checked"'; ?> type = "checkbox" name = "status[]" id = "Approved" value= "Approved"> Approved
<input <?php if(in_array('Pending Application', $_POST['status'])) echo ' checked="checked"'; ?> type = "checkbox" name = "status[]" id = "Pending Application" value="Pending Application"> Pending Application
&#13;
希望能让你走上正轨。注意:虽然有更好的方法可用于通过PHP管理Form元素。寻找任何框架,例如Zend Framework。