dimanche 21 décembre 2014

Codeginiter retriveing values of checked checkbox

Im developing form application. Inside the form there are textboxes,textarea, checkboxes checkboxes are populated according to array. and i pass all the form values to controller . Values of textboxes, texarea print correctly. Problem is there only prints last value of checked checkbox. how do i print all checked box values. please help me & please find the code i used.


askQuestion.php (view)



<?php echo form_open('homepage/test'); ?>

<p>
<div>
<div class="form-group">
Question Title:<br/>

<input type="text" value="" name="">
</p>
<div>

<div class="form-group">
<p>
Description: <br/>

<textarea name="decription" rows="5" cols="100"> </textarea>
</p>

<?php

$chk_group =array('1' => 'red',
'2' => 'aa',
'3' => 'bb',
'4' => 'cc',
'5' => 'dd'

);

var_dump($chk_group);



for ($i=1 ; $i<=count($chk_group);$i++)
{

$val =$chk_group[$i];
echo "<br>";
echo '<input type="checkbox" value="' . $val . '" name="chk_group">' . $val;
echo "</br>";

}

?>


</div>

<div class="form-group">
Declare new Tags:<br/>

<input type="text" value="" name="tag">
</p>
</div>

<p>
<input type="submit" class="btn btn-success btn-block" value="Post Your Question" id="postQuestion">
</p>
<?php echo form_close();?>


homepage.php (controller)



public function test() {
echo "test";
$name = $this->input->post('tag');
print_r($name);

$des = $this->input->post('decription');
print_r($des);

$data = $this->input->post('chk_group');

var_dump($data);

/* foreach ($this->input->post('chk_group') as $r) {
echo $r;
}
*/

}




Aucun commentaire:

Enregistrer un commentaire