Alok Kumar
Alok Kumar

Reputation: 23

Form inside a <tr> tag

I'm including form inside an HTML table tr tag, but it doesn't work for the POST method in the PHP.

I have one table with multiple forms and single tr for load dynamic value from jquery, so I don't have an option to add multiple tr in the table. That's why I want to add my form on the basis of fields.

Let me show one structure for my requirement. This I want to do in my case.

<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
  <form method='Post' action=''>
    <td><input type="text" name="val1"></td>
    <td><input type="number" name="val2"></td>
    <input type="submit" value="Save">
  <form>
   <form method='Post' action=''>
    <td><input type="text" name="val3"></td>
    <td><input type="text" name="val4"></td>
    <td><input type="text" name="val5"></td>
    <input type="submit" value="Save">
  </form>
  </tr>
</table>

I know, if I add the tr inside form then it's working fine, and it's working for me also but I don't have an option to add the tr inside both forms just because of my dynamic jQuery data binding.

How to do that? Thanks in Advance.

Upvotes: 0

Views: 245

Answers (1)

mark_b
mark_b

Reputation: 1471

Your code isn't valid HTML because a table needs to have a structure like

<table>
    <tr>
        <td>
        </td>
    </tr>
</table>

However, you can make use of the HTML5 form attribute. Give your form an ID and place both opening and closing tags inside the same td. Then on each input add a form attribute and use the ID of the form as a value:

<table>
    <tr>
        <td>
            <form id="my-form"></form>
        </td>
        <td>
            <input type="text" form="my-form">
        </td>
    </tr>
</table>

Upvotes: 3

Related Questions