So I have this simplified table from which I'd to choose rows to process. The whole table is wrapped in a form, the submit action is controlled via javascript. I already found out, that when the form-row contains only the checkbox as in form "simple", only the checked items will be passed in the POST action. With additional input fields added to the row as in form "multiple", all rows including the non-checked will be passed. From some days ago I think I remember that by that time I had multiple fields per row and only the checked ones were passed, but I cannot reproduce that any more.
What would be the best way to process only the checked rows? Have a JQuery capturing the $(":checkbox").change event and have that add or remove an JSON object which will get passed by the POST action? Or try to reproduce my previous code with which I think it worked? Or forget the whole idea and have the PHP page processing the POST data loop over the form data and skipping the non-checked? But in large forms with only a few rows checked, that feels like a waste of resources.
<form method="POST" name="multiple">
<table>
<tr>
<td><input type="checkbox" value="a" name="a[id]"></td>
<td>a</td>
<td>description a</td>
<td>...</td>
</tr>
<tr>
<td><input type="checkbox" value="b" name="b[id]"></td>
<td>b</td>
<td>description b</td>
<td>...</td>
</tr>
<tr>
...
</tr>
</table>
</form>
<form method="POST" name="multiple">
<table>
<tr>
<td><input type="checkbox" value="a" name="a[id]"></td>
<td>a</td>
<td><input type="text" value="description a" name="a[description]">description a</td>
<td>...</td>
</tr>
<tr>
<td><input type="checkbox" value="b" name="b[id]"></td>
<td>b</td>
<td><input type="text" value="description b" name="b[description]">description b</td>
<td>...</td>
</tr>
<tr>
...
</tr>
</table>
</form>
Aucun commentaire:
Enregistrer un commentaire