duanlian1960
2015-12-09 14:27
浏览 49

在jquery php codeigniter中动态创建输入字段值

I am trying to get value from dynamic created input field But its not display nothing in page controller.

jQuery code to append dynamic the input

  var tableRow='<tr>';
        tableRow+='<th><input type="text" class="form-control" name="ar[]" placeholder="Nom Articel" id="ar-'+i+'"></th>';
         tableRow+='<th><input type="text" class="form-control" name="des[]" id="des-'+i+'" placeholder="Description"></th>';
       
        $('#' + tableID + ' tbody').append(tableRow);

In the controller I try more then codes but nothing to display

I try to do that:

    $in=$this->input->post("des");
        
if (is_array($in)) {
    foreach ($in as $in => $k) {
      echo "Owner Name is : " . $k . "<br/>";
    }
  } else {
    echo "Owner is not array";
  }

The array exist but empty not value of $k

And I try that

var_dump($this->input->post('des'));

the same nothing display

</div>

图片转代码服务由CSDN问答提供 功能建议

我试图从动态创建的输入字段中获取值但是它在页面控制器中不显示任何内容。

jQuery代码追加动态输入

  var tableRow ='&lt;  tr&gt;'; 
 
 tableRow + ='&lt; th&gt;&lt; input type =“text”class =“form-control”name =“ar []”placeholder =“Nom Articel”id =“ar  - '+  i +'“&gt;&lt; / th&gt;'; 
 
 tableRow + ='&lt; th&gt;&lt; input type =”text“class =”form-control“name =”des []“id =”des-  '+ i +'“placeholder =”Description“&gt;&lt; / th&gt;'; 
 
 
 
 $('#'+ tableID +'tbody')。append(tableRow);  <  / pre> 
 
  
 
  
 
 
 
 

在控制器中我尝试了更多代码但没有显示任何内容

我尝试这样做:

  $ in = $ this-&gt; input-&gt; post(“  des“); 
 
 
 
if(is_array($ in)){
 
 forea  ch($ in in $ in =&gt;  $ k){
 
 echo“所有者名称是:”。  $ k。  “&lt; br /&gt;”; 
 
} 
 
}其他{
 
 
 
 
“所有者不是数组”; 
 
}   
 
   
 
  
 
 
 
 

数组存在但空白而不是$ k的值

我试试

  var_dump($ this-&gt; input-&gt; post('des')); 
   
 
 

相同 没有显示

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongsi073898 2015-12-09 14:37
    已采纳

    Same variables in loop??, it might have overwritten the value posted from form

    foreach ($in as $in => $k) {
                     ^
      echo "Owner Name is : " . $k . "<br/>";
    }
    

    Try changing it to

    foreach ($in as $in1 => $k) {     
      echo "Owner Name is : " . $k . "<br/>";
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题