mardi 24 juillet 2018

How to get checkbox value in codeigniter

Hello friends i have a problem regarding checkbox in codeigniter.I want to send multiple message to different friends by clicking their checkboxes that carries their ids..

THIS IS MY VIEW

                    <tr>
                        <td><input type="checkbox" name="friend_id[]" value=<?php echo $friend->id;?>></td>
                        <td><?php echo $friend->friend_name;?></td>
                    </tr>

THIS IS MY CONTROLLER

public function message(){

$this->form_validation->set_rules('message','Message', 'required');
$this->form_validation->set_rules('friend_id','Recipients', 'required');
if($this->form_validation->run()){
     $data = $this->input->post('friend_id');
     echo '<pre>';
     print_r($data);
     echo '</pre>';
     }
     else{
     echo validation_errors();
        }
     }

When i run it..i get error showing that Recipient is required while i have checked names.




Aucun commentaire:

Enregistrer un commentaire