Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add form to table rows

Which is a valid way (if any) to add a form to table rows?

I have the following situation:

<table>
  <tr>
    <td><input type="text" name="q"></td>
    <td><input type="text" name="a"></td>
    <td><input type="submit" name="submit" value="Submit"></td>
  </tr>
  <tr>
    <td><input type="text" name="q"></td>
    <td><input type="text" name="a"></td>
    <td><input type="submit" name="submit" value="Submit"></td>
  </tr>
  <tr>
    <td><input type="text" name="q"></td>
    <td><input type="text" name="a"></td>
    <td><input type="submit" name="submit" value="Submit"></td>
  </tr>
</table>

How can I add a form element and still have valid HTML?

<table>
  <form>
    <tr>
      <td><input type="text" name="q"></td>
      <td><input type="text" name="a"></td>
      <td><input type="submit" name="submit" value="Submit"></td>
    </tr>
  </form>
</table>

Is invalid (at least I think it is)

like image 388
PeeHaa Avatar asked Jul 15 '11 13:07

PeeHaa


People also ask

How do I add a form to a table?

On the form template, place the cursor where you want to insert the layout table. On the Tables toolbar, click Insert, and then click Layout Table. In the Insert Table dialog box, enter the number of columns and rows that you want to include in the table.

Can you have a form in a table?

You can have a form inside a table cell. You cannot have part of a table inside a form. Use one form around the entire table. Then either use the clicked submit button to determine which row to process (to be quick) or process every row (allowing bulk updates).

Can we use form tag inside table?

It is valid to put a <form> tag inside a <table> tag. Editing note: tags wrapped as code so that the content reads as intended, but the answer should specify that while the form is inside the table, it cannot be a direct descendant: it must be a child of a cell.


1 Answers

Wrap your table inside the form element:

<form action="/" name="form1">
  <table>...</table>
</form>

But even better: Build your form without tables if possible.

like image 129
Mario Uher Avatar answered Sep 16 '22 12:09

Mario Uher