I have this form:
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>Birthdate</th>
<th><input type="text" autofocus="autofocus" name="textinput1"/></th>
<th><input type="checkbox" name="checkinput[]" value="1"/></th>
</tr>
<tr>
<th>ID</th>
<th>Name</th>
<th>Birthdate</th>
<th><input type="text" autofocus="autofocus" name="textinput2"/></th>
<th><input type="checkbox" name="checkinput[]" value="1"/></th>
</tr>
(...and so on...)
</tbody>
Is there a way when I click in the submit button, the post data be in a array type, where each index have the checkbox value and the text input? This way I only have to iterate the array and for each row in the form check the respective row in database and update it.
Make the text input boxes into arrays, and put the value for the array keys into your HTML:
Then when you iterate, you do something like this:
Note that this will not tell you if the checkbox was checked, since only checked checkboxes are sent to the server from the browser. To do this, modify the checkboxes to also include an array key:
Then, change the
foreachloop to this: