2017-04-22 74 views
2

我想發佈複選框值並存儲它,但我的帖子值顯示爲on。在php中發佈複選框值

查看

<label for="name">Programme Applied for:</label><br> 
<br> 
<input name="program" type="checkbox">Six Months Computerized Accounting Diploma<br> 
<input name="program" type="checkbox">Six Months Computerized Accounting Diploma<br> 
<input name="program" type="checkbox">Two Months Diploma in taxation (Direct)<br> 
<input name="program" type="checkbox">Three Months Diploma in taxation (Direct & Indirect)<br> 
<input name="program" type="checkbox">One Year Diploma in Accounting Finance Taxation <br> 
<input name="program" type="checkbox">Banking and Payroll 
<br><br> 
<div class="clear"></div> 
<div class="text-danger"><?php echo form_error('program'); ?></div> 

控制器

$data=array('prg_applied' => $this->input->post('program')); 
$insert = $this->firstmodel->insert_record($data); 
+0

你已經有值字段 –

回答

2

你必須有值字段,如果你沒有值字段,然後它會顯示 「上的」 選中的複選框

<input name="program" type="checkbox" value='Three Months Diploma in taxation (Direct & Indirect)'>Three Months Diploma in taxation (Direct & Indirect)<br> 
+0

謝謝它的工作。 – dipti

1

它看起來像你想radio而不是複選框。然後,您可以有多個可選擇的輸入name和不同的value,其中所選框將在HTTP請求中提供值。

您還使用<label>錯誤。它應該是各個輸入:

<label><input name="program">Six Months Computerized…</label><br> 

或者:

<input name="program" id="x"> <label for="x">Six Months Computerized…</label><br>