2015-10-12 81 views
0

即時通訊相當新的PHP和我一直有麻煩的形式保存爲radioboxes,複選框的內存&(下拉)選擇列表中的形式,放或選擇將仍然存在,當我提交。表單輸入內存爲radioboxes,複選框和下拉(選擇)形式

\t \t <select name = "province[]" multiple size = "12"> 
 
\t \t \t \t 
 
\t <?php foreach ($PROVINCES as $key => $value) {?> 
 
    <option value = "<?php echo $value ?>"<?php (in_array('$key',$_POST['province']))?'selected':'';?>><?php echo $value ?></option> \t \t \t \t 
 
<?php }?> 
 
\t \t \t \t </select> \t 
 
\t \t \t <br><br> 
 
\t <label for = "status">Status(Mult Select)<font color = "red">*</font></label> 
 
\t <input type = "checkbox" name = "status[]" id = "Approved" value= "Approved"> Approved 
 
\t <input type = "checkbox" name = "status[]" id = "Pending Application" value="Pending Application"> Pending Application 
 
\t <input type = "checkbox" name = "status[]" id = "Active Service" value="Active Service"> Active Service 
 
\t \t \t <br><br> 
 
\t <label for = "location">Location<font color = "red">*</font></label> 
 
\t <input type = "radio" name = "location" id = "Garage" value = "Garage"> Garage 
 
\t <input type = "radio" name = "location" id= "Attic" value = "Attic"> Attic 
 
\t <input type = "radio" name = "location" id = "House" value = "House"> House 
 
\t \t \t </fieldset>

+0

看到複選框的屬性['checked'](https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/checkbox)。它也可以用於單選按鈕。 – HPierce

回答

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

希望,將讓你的軌道上。注意:有可用的管理,雖然通過PHP表單元素更好的方法。尋找任何框架,例如Zend框架。

+0

一些奇怪的原因,它正在改變盒子放在文本 – rich

+0

嗯..那是什麼「運行代碼片段」一樣。事實上,當你把這個腳本,並在服務器端運行它,它運行良好。保存在一些PHP文件中的代碼並運行它;應該很好。 – jpaljasma