2016-06-07 65 views
3

这是我的看法笨复选框破灭功能错误

<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"> &nbsp;save</i> </button> 
     <button class="btn btn-default" type="reset" > <i class="fa fa-ban">&nbsp;cancel</i></button> 
    </div> 
</div> 

这里是我的控制器

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); 
     } 

当我加载视图添加新CAMPANY,我得到了错误:

一遇到PHP错误 严重性:警告消息:implode():传递的参数无效 行号:41

任何机构都可以帮忙!

+0

如果您使用双qoutes会发生什么? $ PROD =破灭( “”,$这 - >输入 - >柱( '产品')); – Swolschblauw

+0

双引号同样的问题 –

+0

您正在使用相同的方法来加载添加视图并保存添加视图? –

回答

1
  1. 甲PHP错误遇到严重性:警告消息:破灭():无效参数传递行号:41

上述错误会如果$this->input->post('products')值是空的或不是阵列。确保你有数组值。

  1. 我试过了你的代码。它只工作正常。请通过它。

    我用这个视图页。

    <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"> &nbsp;save</i> </button> 
        <button class="btn btn-default" type="reset" > <i class="fa fa-ban">&nbsp;cancel</i></button> 
           </div> 
    
           </form> 
    

而在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); 
    } 

虽然我使用的print_r($数据);它为我工作正确。

+0

虽然我使用print_r($ data)它显示Array([nomsoc] => [specialitesoc] => [produitssoc] = > [activitessoc] => [dirigeantsoc] => [telsoc] => [faxsoc] => [ville] => [adressesoc] => [facebooksoc] => [twittersoc] => [gplussoc] => [linkedinsoc] = > [youtubesoc] => [emailsoc] =>) –

+0

但是也存在错误 –

+0

您是否更改了视图文件中的任何内容。 –