CodeIgniter Forums
Cant get values of checkboxes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Cant get values of checkboxes (/showthread.php?tid=678)



Cant get values of checkboxes - mastercho - 01-05-2015

Im trying to insert multiple checkboxes but cant get their values in codeigniter 2

this is my code in View

PHP Code:
  <!-- Multiple Checkboxes (inline) -->
                   <div class="form-group">
                     <div class="col-md-4">
                       <label class="checkbox-inline" for="checkboxes-0">
                         <input type="checkbox" name="checkboxes[]" id="checkboxes-0" value="22">
                         Пентхаус
                       
</label>
                         <br>
                   <!-- Text input-->
                   <div class="form-group">
                     <div class="col-md-8">
                     <input id="cena" name="cena[]" type="text" placeholder="Въведи цена" class="form-control input-md">

                     </div>
                   </div>

                       <label class="checkbox-inline" for="checkboxes-1">
                         <input type="checkbox" name="checkboxes[]" id="checkboxes-1" value="21">
                         Гараж/Паркомясто
                       
</label>
                   <br>
                                           <!-- Text input-->
                   <div class="form-group">
                     <div class="col-md-8">
                     <input id="cena" name="cena[]" type="text" placeholder="Въведи цена" class="form-control input-md">

                     </div>
                   </div
This is my Model:

PHP Code:
   public function InsertCheckbox() {

          $property_typesRequest $this->input->post('checkboxes');
           foreach($property_typesRequest as $value){
           $this->db->insert_batch('property_type_details'$property_typesRequest);

           }


in Controller i just use this:

PHP Code:
       $this->estate_m->InsertCheckbox(); 
And this going insert 0 in database, when i var_dump $property_typesRequest theres shows bool(false). I cant get values of checkboxes...

EDIT...

I have try to edit my code but still no result:

PHP Code:
 public function edit()/*this is  controller */
 
   $data
=array('column_name'=>$this->input->post('checkboxes');
   $result=$this->estate_m->InsertCheckbox($data);
   if($result==true)
   {
           echo "Success";
   }
   else
   
{
           echo "Fail";
   }

}
public function 
InsertCheckbox($data/*this is Model */
      
   $this
->db->insert('property_type_details'$data);
   return ($this->db->affected_rows() != ) ? false true;


With this edited code always gives me Succes


RE: Cant get values of checkboxes - bclinton - 01-05-2015

Perhaps this is a dumb question but are you checking your checkboxes? $this->input->post('checkboxes') will return false if none of them are checked.


RE: Cant get values of checkboxes - Avenirer - 01-06-2015

Well... you did a foreach... but you didn't use the value (you used the array)...


PHP Code:
foreach($property_typesRequest as $value){
 
          $this->db->insert_batch('property_type_details'$property_typesRequest);

 
          

Also, if you do a foreach, why do you do an insert_batch(), and not an insert()?


RE: Cant get values of checkboxes - mastercho - 01-06-2015

Problem sloved! http://stackoverflow.com/questions/27776228/cant-get-values-of-checkboxes-in-codeigniter
Thanks for your time!