here view
<input type="text" name="name" class="form-control" placeholder="name" /> <div class="col-sm-12"> <select name="speciality" class="form-control" required > <option value="" selected="selected" >liste speciality</option> <option value="ag" >spec1</option> <option value="al" >spec2</option> <option value="pvc">spec3</option> <option value="medc">spec4</option> </select> </div> <div class="col-sm-9"> <label class="checkbox-inline"> <input type="checkbox" value="parquet" name="products[]"> product1 </label> <label class="checkbox-inline"> <input type="checkbox" value="fplancher" name="products[]"> product2 </label> <label class="checkbox-inline"> <input type="checkbox" value="fauxplafonddem" name="products[]"> product3 </label> <label class="checkbox-inline"> <input type="checkbox" value="cloison" name="products[]"> product4 </label> <label class="checkbox-inline"> <input type="checkbox" value="cloisonamovible" name="products[]"> product5 </label> <div class="bottom"> <button class="btn btn-primary" name="btnadd" value="1" type="submit"> <i class="fa fa-mail-reply-all"> save</i> </button> <button class="btn btn-default" type="reset" > <i class="fa fa-ban"> cancel</i></button> </div> </div>
here controller
public function add() { $prod=implode(',',$this->input->post('products')); $data=array('nomsoc'=>$this->input->post('name'), 'specialitesoc'=>$this->input->post('speciality'), 'produitssoc'=>$prod); if ($this->input->post("btnadd", false)) { if($this->societemodel->add($data)) { $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">société ajoutée avec succès </div>'); redirect("/societe/"); } } $this->layout->title(' campany title'); // set page title $this->loadviewblocks("societe","","",true,true,true); $data["bodyid"]="register-bg"; $this->layout->view('backend/societe/add', $data); }
when load view add new campany, got error :
a php error encountered severity: warning message: implode(): invalid arguments passed line number: 41
any body can please!
- a php error encountered severity: warning message: implode(): invalid arguments passed line number: 41
above error come if $this->input->post('products')
value empty or not array. make sure have array values that.
i have tried code. working fine only. please go through on it.
i used view page.
<form action="<?php echo base_url(); ?>index.php/forms/add" method="post"><input type="text" name="name" class="form-control" placeholder="name" /> <div class="col-sm-12"> <select name="speciality" class="form-control" required > <option value="" selected="selected" >liste speciality</option> <option value="ag" >spec1</option> <option value="al" >spec2</option> <option value="pvc">spec3</option> <option value="medc">spec4</option> </select> </div> <div class="col-sm-9"> <label class="checkbox-inline"> <input type="checkbox" value="parquet" name="products[]"> product1</label> <label class="checkbox-inline"> <input type="checkbox" value="fplancher" name="products[]"> product2</label> <label class="checkbox-inline"> <input type="checkbox" value="fauxplafonddem" name="products[]"> product3</label> </div> <label class="checkbox-inline"> <input type="checkbox" value="cloison" name="products[]"> product4 </label> <label class="checkbox-inline"> <input type="checkbox" value="cloisonamovible" name="products[]"> product5 </label> <div class="bottom"> <button class="btn btn-primary" name="btnadd" value="1" type="submit"> <i class="fa fa-mail-reply-all"> save</i> </button> <button class="btn btn-default" type="reset" > <i class="fa fa-ban"> cancel</i></button> </div> </form>
and in mycontroller
public function add() { $prod=implode(',',$this->input->post('products')); $data=array('nomsoc'=>$this->input->post('name'), 'specialitesoc'=>$this->input->post('speciality'), 'produitssoc'=>$prod); print_r($data); exit(); if ($this->input->post("btnadd", false)) { if($this->societemodel->add($data)) { $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">société ajoutée avec succès </div>'); redirect("/societe/"); } } $this->layout->title(' campany title'); // set page title $this->loadviewblocks("societe","","",true,true,true); $data["bodyid"]="register-bg"; $this->layout->view('backend/societe/add', $data); }
while used print_r($data); worked correctly me.