Avoid nested forms in table
How would one create the following valid (x)HTML where the checkboxes and radiobuttons (column 3 and 4) and save button are all part of one big form, and all the delete buttons (last column) are submit buttons of their own individual forms (having a hidden field with the id of the locale), without using javascript?
language | reg开发者_Python百科ion | active | default |
-----------------------------------------------
en | GB | [x] | (*) | X delete
nl | NL | [x] | ( ) | X delete
nl | BE | [x] | ( ) | X delete
[save]
Using a table, I end up having to nest forms, which of course is invalid. So, I was wondering, what other possibilities I have. Floating columns perhaps?
You can use a single form. Make use of the fact that the name-value pair of the pressed button will be sent as request parameter as well. During populating of the HTML form, dynamically inline the locale ID in the name of the button.
<input type="submit" name="delete_1" value="Delete" />
<input type="submit" name="delete_2" value="Delete" />
<input type="submit" name="delete_3" value="Delete" />
And then in the server side check if any of them have been pressed (pseudo/Java-style):
for (Locale locale : locales) {
if (request.getParameter("delete_" + locale.getId()) != null) {
// Delete button is pressed for this locale.
}
}
You can use two different tables - one with a single form for the checkboxes, radiobuttons and save button and the second one with the delete buttons and hidden field.
Simply use CSS to reposition these next to each other.
精彩评论