如何从codeigniter中的<input type =“text”name =“mytextfield []”/>获取值

时间:2013-06-18 04:41:59

标签: codeigniter

<script type="text/javascript">

function addField(){

    var newContent = "<li><input type='text' name='mytextfield[]'/></li>";

    $("#myfields").append(newContent); 
}
</script>

<input type='text' name='mytextfield[]' />

<div id='addmorelink'>
    <a href='javascript:addField()'>add more contact</a>
</div> 

这是我的视图代码...我需要从输入字段'mytextfield []'获取数据,这是一个动态字段。

2 个答案:

答案 0 :(得分:0)

当你在控制器中发布数组数据时,你应该把它作为像这样的post数组

function add_records()
{
   //this $name is array
   $name = $this->input->post('name');

   //you can use a foreach loop to insert these data to the data base or you can use
   //codeigniter insert_batch function
}

答案 1 :(得分:0)

使用

$contacts = $this->input->post('mytextfield');

foreach($contacts as $key=>$val){
// process them as you like

}