希望修改现有系统,该系统添加了UOM下拉选择字段。我想把我选择的值拿到我的CodeIgnitor控制器,但它似乎不起作用。
<tbody id="dataTable" style="background: #cccccc ">
<tr>
<!--<td><input type = "checkbox" name="chkbox[]"/></td>-->
<td></td>
<td><input required type="text" name="item[]"/></td>
<td><input required type="text" name="price[]" /></td>
<td><input required type="text" name="qty[]" /></td>
<td><select required type="text" name="uom[]">
<option value = "">--Please Select--</option>
<option value = "PCS">PCS - Pieces</option>
<option value = "M">M - Meters</option>
<option value = "KG">KG - Kilograms</option>
<option value = "BOX">BOX - Boxes</option>
<option value = "SET">SET - Sets</option>
<option value = "CTN">CTN - Cartons</option>
<option value = "PLT">PLT - Pallets</option>
<option value = "ROLL">ROLL - Rolls</option>
<option value = "PKT">PKT - Packets</option>
</select>
</td>
</tr>
下面是我的控制器:
public function user_data_submit() {
$data = array(
//'tranh_item_uom' is my uom database's column
'tranh_item_uom'=>$this->input->post('uom1'),
'tranh_item_uom2'=>$this->input->post('uom2'),
'tranh_item_uom3'=>$this->input->post('uom3'),
'tranh_item_uom4'=>$this->input->post('uom4'),
'tranh_item_uom5'=>$this->input->post('uom5'),
);
}
运气不好,不能让它正常工作。很抱歉,我最近刚刚学习了codeignator和php,仍然不太熟悉。
我在这里的完整代码:
- Controller.php->https://codepen.io/Kezn/pen/QWWQywb
- Viewer.php->https://codepen.io/Kezn/pen/WNNMrvv
要获得所有的uom[]
输入,您可以像这样组成$data
数组:
public function user_data_submit() {
$uoms = $this->input->post('uom');
$data = [];
foreach ($uoms as $key => $value) {
reset($uoms);
$i = $key;
if ($key === key($uoms)) {
$i = ''; // set first array item key as empty
}
$data[$key] = [
"tranh_item_uom$i" => $value
];
}
}