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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?