Welcome Guest, Not a member yet? Register   Sign In
Cant get values of checkboxes
#1

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
Reply
#2

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.
Reply
#3

(This post was last modified: 01-06-2015, 07:56 AM by Avenirer.)

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()?
Reply
#4

Problem sloved! http://stackoverflow.com/questions/27776...odeigniter
Thanks for your time!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB