2016-06-07 66 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

您是否更改了視圖文件中的任何內容。 –