如何获取此表格数据并正确分组字段?

时间:2013-10-20 00:10:45

标签: php html arrays forms input

我有一个用户将填写的输入字段表。如您所见,有两对字段,四列并且最少五行,可以根据需要动态添加更多行。我一直在努力如何命名输入字段,以便在提交表单时将它们正确地组合在一起。我尝试了不同的行等等,但没有一个工作得很好。我希望每一对都在一个阵列中,即

[0] -> drum - value
[0] -> size - value
[1] -> drum - value
[1] -> size - value

这是我现在拥有的表格。非常感谢你的帮助,我真的很感激!

<table id="drumInformation">
        <tr>
            <th colspan="9"><p>D R U M I N F O R M A T I O N – Drum Number(s) / Liter(s) or Gallon(s) Used</p>

                <p> If some or all of your drum numbers fall in consecutive order, please feel free to use the
                    "series" method shown below to avoid typing each drum number individually and to save you valuable time.</p>

                <p>Example:<br/>
                    10001, 10002, 10003, 10004, 10005, 10006 or 10001 - 10006</p>
            </th>
        </tr>
        <tr class="labelRow">
            <td class="label">
                <label>Drum No.</label>
            </td>
            <td class="label">
                <label><span class="euro">Liters</span><span class="domestic">Gallons</span></label>
            </td>
            <td class="label">
                <label>Drum No.</label>
            </td>
            <td class="label">
                <label><span class="euro">Liters</span><span class="domestic">Gallons</span></label>
            </td>
            <td class="label">
                <label>Drum No.</label>
            </td>
            <td class="label">
                <label><span class="euro">Liters</span><span class="domestic">Gallons</span></label>
            </td>
            <td class="label">
                <label>Drum No.</label>
            </td>
            <td class="label">
                <label><span class="euro">Liters</span><span class="domestic">Gallons</span></label>
            </td>
        </tr>
        <tr>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td class="remove"></td>
        </tr>
        <tr>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td class="remove"></td>
        </tr>
        <tr>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td class="remove"></td>
        </tr>
        <tr>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td class="remove"></td>
        </tr>
        <tr>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td>
                <input name="row[][drumNumber][]">
            </td>
            <td>
                <input name="row[][gallons][]">
            </td>
            <td class="remove"><img src="/forms/assets/img/Plus-32.png" class="addRow"></td>
        </tr>

    </table>

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,可以将表行更改为:

    <tr>
        <td>
            <input name="group[8][drumNumber]">
        </td>
        <td>
            <input name="group[8][gallons]">
        </td>
        <td>
            <input name="group[9][drumNumber]">
        </td>
        <td>
            <input name="group[9][gallons]">
        </td>
        <td>
            <input name="group[10][drumNumber]">
        </td>
        <td>
            <input name="group[10][gallons]">
        </td>
        <td>
            <input name="group[11][drumNumber]">
        </td>
        <td>
            <input name="group[11][gallons]">
        </td>
        <td class="remove"></td>
    </tr>

可能有更清洁的解决方案,但这个有效。我不知道为什么我会在前面放任何东西。