0

My html structure looks like below:

<table class="table">
   <thead>
      <tr>
         <th>Name</th>
         <th>Email</th>
         <th>Category</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>John</td>
         <td>john@live.nl</td>
         <td>
            <form method="post" action="admin.php>
               <input type="text" ........
               <input type="text" ........
               <button type="submit" name="change_category">Update</button>
            </form>
         </td>
      </tr>
   </tbody>
</table>

When i check it in the validator https://validator.w3.org/; it does not give me an error. But i am not sure if this is correct...

Because, according to this topic: Form inside a table ; it is not allowed

john
  • 1,263
  • 5
  • 18
  • 2
    Yes, it's valid. Please read the errors more carefully, as they fully explain what is wrong and why the validator has returned invalid... – BenM Dec 27 '19 at 11:41

2 Answers2

2

Yes, you can add form inside a td tag, there isn't any restriction related to which tag can be parent of form tag as long it's wrap inside the opening and closing tag.

This is commun use case when you have a table like this

<table>
  <tr>
    <td>ID></td>
    <td>Name</td>
    <td>Description</td>
    <td>Actions</td>
  </tr>
  <tr>
    <td>1</td>
    <td>First Article</td>
    <td>Description for first article</td>
    <td>
      <a href="...">View</a>
      <form method="post" action="...">
        <input type="submit" value="Delete">
      </form>
    </td>
  </tr>
</table>

in the actions column I have action which allow to delete data in a specific row inside the table, and that action is performed using the POST method

Yves Kipondo
  • 5,289
  • 1
  • 18
  • 31
1

Yes. Form can be placed inside <td> tag of the table.

upd. In the last example form is placed inside <tr>, this is not best practice, yes, but I see in your code you placed form inside <td>, it is fully okay.

Alex
  • 2,707
  • 4
  • 29
  • 42