Php Codeigniter-发送到控制器时附加的数组项丢失
我有一个查看页面Php Codeigniter-发送到控制器时附加的数组项丢失,php,jquery,arrays,codeigniter,Php,Jquery,Arrays,Codeigniter,我有一个查看页面 $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="d
$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(); ?>
我只能获取已提供给查看页面的数组的第一项。附加的数组项丢失。有人能帮我吗?您的HTML代码工作正常。问题来自jquery或add按钮。如果要使用html按钮标记,那么必须在jquery中使用preventDefault()
$('.add').click(function(e){
e.preventDefault();
$("#companytable").append('<tr><td><input type="text" name="companyname[]" class="cmp_textbx" placeholder="Enter Company"></td></tr>');
});
$('.add')。单击(函数(e){
e、 预防默认值();
$(“#公司表”)。追加(“”);
});
或者,您可以在选择“键入为”按钮时使用输入,因此您不需要对代码进行任何更改。感谢@prasanna puttaswamy的回复。实际上,我使用的是一个标签,而不是添加公司的按钮。对不起,这是误导性的信息。你能在jquery中添加完整的问题表格吗?@Gyandeep Sharma我已经对这个问题进行了编辑。请检查它。您的代码运行良好…
echo”“;打印(邮政美元)代码>在控制器/文件上传功能上尝试此代码。很抱歉,它仍然无法工作。印刷品(邮政美元);给出答案数组([companyname]=>Array([0]=>fgfdg)[btn_upload]=>Save),这只是第一个数组项请看我没有更改代码中的任何内容。。它工作得很好。。。谢谢大家宝贵的时间。
$company_items = array();
$company_items = $this->input->post('companyname');
print_r($company_items);
$('.add').click(function(e){
e.preventDefault();
$("#companytable").append('<tr><td><input type="text" name="companyname[]" class="cmp_textbx" placeholder="Enter Company"></td></tr>');
});