【发布时间】:2018-06-17 01:59:16
【问题描述】:
我有一个查看页面
$nameArray = array('name' => 'Formname', 'id' => 'Formname');
echo form_open_multipart('controller/file_upload_function',$nameArray);
<table id="companytable" >
<tr><td><input type="file" id="dummyfile" name="dummyfile"></td></tr>
<tr>
<td >
<label id="addlabel" style="cursor: pointer;">
<i class="fa fa-plus-circle" aria-hidden="true"></i></label>
</td>
<tr>
<td>
<input type="text" name="companyname[]" class="cmp_textbx" placeholder="Enter Company">
</td>
</tr>
<tr>
<td>
<input type="submit" id="btn_upload" name="btn_upload" value="Save">
</td>
</tr>
</table>
<?php echo form_close(); ?>
使用 Jquery 我需要根据用户附加更多的“公司名称”字段(点击“添加公司”标签)。“公司表”是表的 ID。
$("#addlabel").click(function(){
$("#companytable").append('<tr><td><input type="text" name="companyname[]" class="cmp_textbx" placeholder="Enter Company"></td></tr>');
});
问题是当我尝试提交我的视图并尝试获取数组项“公司名称”时。
$company_items = array();
$company_items = $this->input->post('companyname');
print_r($company_items);
我只能获取已经给定视图页面的数组的第一项。附加的数组项丢失了。有人可以帮助我吗?
【问题讨论】:
-
您的代码运行良好...
-
echo "<pre>";print_r($_POST);在控制器/file_upload_function 上试试这个代码。 -
抱歉还是不行。 print_r($_POST);给出答案 Array ( [companyname] => Array ( [0] => fgfdg ) [btn_upload] => Save ) 那只是第一个数组项
-
请看我没有更改您的代码中的任何内容。它运行良好...Output
-
感谢大家的宝贵时间。
标签: php jquery arrays codeigniter