我的形式如下图所示:
// supplier info
$supplier_name = $_POST['supplier_name'];
$supplier_sending = $_POST['supplier_sending'];
$supplier_guarantee = $_POST['supplier_guarantee'];
$supplier_price = $_POST['supplier_price'];
$supplier_colors = $_POST['supplier_colors'];
$supplier_info = array($supplier_name,
$supplier_sending,$supplier_guarantee, $supplier_price, $supplier_colors);
$proSupply = json_encode($supplier_info);
通过这种方式,我可以成功地将$proSupply
var提交到我的表中。但正如您在打印屏幕中看到的那样,我添加了一个名为添加更多供应商的链接:+它的作用基本上为表单添加了一个新的表行。因此用户可以插入多个供应商信息。
但问题是我的桌子上只有一个应包含供应商信息的字段。而且因为我不知道用户想要添加多少供应商,所以我无法指定MySQL表中提交的供应商数量。
所以我的问题是:当用户点击PHP中的+链接(例如supplier_info_1,supplier_info_2等)时,有没有办法在表中创建一个新的自定义字段?
更新1:
这是为我的表格提供新行的脚本。
<script>
$("#addbtn").click(function(){
var next = parseInt($('#counter').val()) + 1;
$("#group").append("<table class='table table-hover'>
<tr>
<th style='padding-left:10px'>Name of supplier ("+next+")</th>
<th>Terms of sending</th>
<th>Guarantee</th>
<th>Price</th>
<th>Colors (use , for separation)</th>
</tr>
<tr>
<td style='padding-left:10px'><input name='supplier_name_("+next+")' type='text'></input></td>
<td><input name='supplier_sending_("+next+")' type='text'></input></td>
<td><input name='supplier_guarantee_("+next+")' type='text'></input></td>
<td><input name='supplier_price_("+next+")' type='text'></input></td>
<td><input name='supplier_colors_("+next+")' type='text'></input></td>
</tr>
</table>");
$('#counter').val(next);
});
</script>
是的,我的库存和会计软件中有类似的概念。你可以使用javascript或更好的jquery来处理它。您可以为供应商创建隐藏行。当根据您的应用程序触发事件时,将创建一个副本以获取另一个供应商行。