表单中可变数量的输入字段 [英] Variable number of input fields in form
问题描述
我有一个 HTML 表格基础发票,用于收集订单的详细信息.可以根据用户需要添加或删除新的表行.表中有项目名称、类型、颜色、单价、数量等列.我在 I have a HTML table base invoice for collecting the details of a order. New table rows can be added or deleted to this as the user needs them. Table has columns like item name, type, color, unit price, qty. I have place 我需要向数据库提交完整的发票.我遇到的问题是我不确定如何将输入值输入到我的 I need to submit a complete invoice to a database. The problem I'm having is I'm not sure how to get input values to my 当使用 javascript 生成时,我可以根据表行 ID 为输入字段提供动态或静态名称.但是如何在提交端将这些数据收集到我的 php 数组或变量中? I can give dynamic or static names to input fields based on the table row id when they are generated using javascript. But how can I collect these data in the submit end to my php arrays or variables? 这是一个表格行.所有其他都与此类似. This is one table row. All other are similar to this. 请给我一些想法来实现我的想法. Please give me some ideas to implement my idea. 将所有不同的部分封装在数据库中单独的表中.这样您就可以单独存储它们并通过外键相互关联. encapsulate all the varying parts in separate tables in the database. so you can store them separately and relate to each other with foreign keys. 对于 HTML 输入使用数组命名也是一个好主意,例如 also it's a good idea to use array naming for you HTML inputs like 这为您提供了更加结构化且易于迭代的数据. this gives you data, which is more structured and easy to iterate. 这篇关于表单中可变数量的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 标签内放置了 和
标签来收集数据.
<input>
and <select>
tags inside <td>
tags to collect data.$_POST
变量中,因为 <input>
和 <select>
根据发票上的项目不时变化.$_POST
variables since the number of <input>
and <select>
vary from time to time based on the items on the invoice.<tr class="table_row_blue">
<td class="table_data_index">1</td>
<td><select>
<option>Test</option>
</select></td>
<td class="table_data_item"><select>
<option> 2GB </option>
</select></td>
<td><input type="text" id="price_field" size="6"></td>
<td><input type="text" id="qty_field" size="6"></td>
<td><span class="table_subtotal">125,200.00</span></td>
</tr>
推荐答案
<input name="data[Invoice][field1]" />
<input name="data[Invoice][field2]" />
登录
关闭