HTML: table of forms?

后端 未结 2 683
面向向阳花
面向向阳花 2020-12-17 02:10

I frequently find myself wanting to make a table of forms -- a bunch of rows, each row being a separate form with its own fields and submit button. For instance, here\'s an

相关标签:
2条回答
  • 2020-12-17 02:33

    The trick here is to just use a single form, e.g.

        <form>
          <table>
            <!-- rows... -->
          </table>
          <p><input type="submit" value="Update quantity"></p>
        </form>
    

    Say you have a product snake with id 6. You then name the input for that item's quantity field quantity[6].

    I don't know what server side language you are using, but in PHP you can then iterate over the quantites and update based on the ID. You'd get an array like this:

    $_POST['quantity'] = array(
        '6' => 4
    )
    
    0 讨论(0)
  • 2020-12-17 02:40

    You can use css to give table layout to other elements.

    .table { display: table; } 
    .table>* { display: table-row; }
    .table>*>* { display: table-cell; }
    

    Then you use the following valid html.

    <div class="table"> 
        <form>
            <div>snake<input type="hidden" name="cartitem" value="55"></div>
            <div><input name="count" value=4/></div>
        </form>
    </div>
    
    0 讨论(0)
提交回复
热议问题