samedi 28 octobre 2017

PHP retrieve unchecked checkboxes for array

I am getting ($_POST) different values comeing from checkboxes. (this row is repating N times)

<tr>
<td>All members <input type="hidden" name="group[]" value="0" /> <input type="hidden" name="project[]" value="<?php echo $_GET['id']; ?>" /></td>
                            <td align="middle"><input type="checkbox" rowid="0" columnid="1" name="read[]" value="1" <?php echo io($perm['read'],"checked"); ?>/></td>
                            <td align="middle"><input type="checkbox" rowid="0" columnid="2" name="open[]" value="1" <?php echo io($perm['open'],"checked"); ?> /></td>
                            <td align="middle"><input type="checkbox" rowid="0" columnid="3" name="comment[]" value="1" <?php echo io($perm['comment'],"checked"); ?> /></td>
                            <td align="middle"><input type="checkbox" rowid="0" columnid="4" name="edit[]" value="1" <?php echo io($perm['edit'],"checked"); ?> /></td>
                            <td align="middle"><input type="checkbox" rowid="0" columnid="5" name="mod[]" value="1" <?php echo io($perm['mod'],"checked"); ?> /></td></tr>

When I post them, I retrieve them with:

for ($i = 0; $i < count($group_array); $i++) {
                            $group = mysqli_real_escape_string($con,$group_array[$i]); [...]

The problem is that if a checkbox input is not checked, it is not added in the array.

So does anyone know how I could manage this situation?

A radio input would be perfect (I would have a value posted in any case... but with checkbox, it is yes or no. And as I have them stored as an array, I can't manage them one by one)




Aucun commentaire:

Enregistrer un commentaire