dtf54486 2011-06-18 07:11
浏览 95
已采纳

表单中可变数量的输入字段

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 <input> and <select> tags inside <td> tags to collect data.

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 $_POST variables since the number of <input> and <select> vary from time to time based on the items on the invoice.

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.

<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>&nbsp;2GB&nbsp;</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>

Please give me some ideas to implement my idea.

  • 写回答

3条回答 默认 最新

  • dqgo99177 2011-06-18 07:19
    关注

    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.

    also it's a good idea to use array naming for you HTML inputs like

    <input name="data[Invoice][field1]" />
    <input name="data[Invoice][field2]" />
    

    this gives you data, which is more structured and easy to iterate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大