在php中发布复选框值

时间:2017-04-22 08:46:32

标签: php codeigniter

我想发布复选框值并存储它,但我的帖子值显示为on。

查看

<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);

2 个答案:

答案 0 :(得分:2)

您必须拥有值字段,如果您没有值字段,那么它将显示&#34; on&#34;对于复选框

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

答案 1 :(得分: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>