To add a <form>
tag in each table row in HTML, we can simply enclose each row within a <form>
tag.
For example, we write:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forms in Table Rows</title>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<form action="/submit" method="post">
<td><input type="text" name="name"></td>
<td><input type="email" name="email"></td>
<td><button type="submit">Submit</button></td>
</form>
</tr>
<tr>
<form action="/submit" method="post">
<td><input type="text" name="name"></td>
<td><input type="email" name="email"></td>
<td><button type="submit">Submit</button></td>
</form>
</tr>
<!-- Add more rows as needed -->
</tbody>
</table>
</body>
</html>
Each <tr>
element is enclosed within a <form>
tag.
And each row contains form elements such as <input>
fields for name and email, and a submit button.
The action
attribute of the <form>
tag specifies the URL where the form data will be sent upon submission.
The method
attribute of the <form> tag specifies the HTTP method to use when sending form data (e.g., “post” or “get”).
By enclosing each table row within a <form>
tag, you can create multiple forms within a table, with each form representing data for a specific row.