0

我有这个用户将填写的输入字段表。如您所见,有两对字段,四列和至少五行长度,并且能够根据需要动态添加更多行。我一直在为如何命名输入字段而苦苦挣扎,以便在提交表单时将它们正确组合在一起。我尝试了不同的行变体等,但没有一个工作得很好。我希望每一对都在一个数组中,即

[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>
4

1 回答 1

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>

可能有一个更清洁的解决方案,但这一个有效。我不知道为什么我坚持把 row[] 放在前面。

于 2013-10-20T00:58:53.137 回答