sid_com sid_com - 7 months ago 33
HTML Question

form within table-row tag

Is it OK to write a

form
within the
tr
tag?

<table>
% for my $word ( @$words_2 ) {
<tr>
<form action="/blacklist" method="post">
<td><%=$word%></td>
<td><input type="text" name="data" readonly hidden value="<%=$word%>" /></td>
<td><input class="remove" type="submit" value="Remove" /></td>
</form>
</tr>
% }
</table>

Answer

The tr doesn't allow form-tags as direct children. Most modern browsers will let you do a lot of crap and so you could use this - but I wouldn't call it OK. A better approach would be to but the complete form into one of the tds (tds allow text, forms, inline- and block-elements as children):

<table>
    <% for my $word ( @$words_2 ) { %>
        <tr>
            <td><%=$word%></td>
            <td>
              <form action="/blacklist" method="post">
                <input type="text" name="data" readonly hidden value="<%=$word%>" />
                <input class="remove" type="submit" value="Remove" />
              </form> 
            </td>
        </tr>
    <% } %>
</table>

or, a lot easier, simply use a link (but note that data gets sent using GET instead of POST - maybe you'll have to change something in your code that handles the blacklisting):

<table>
    <% for my $word ( @$words_2 ) { %>
        <tr>
            <td><%=$word%></td>
            <td><a href="/blacklist?data=<%=$word%>">Remove</a></td>
        </tr>
    <% } %>
</table>
Comments