jeudi 21 janvier 2021

PHP checkbox validation checked or not checked

I've been using similar code to this for my project and I'm able to get all of the "Checked" checkboxes using the $_POST[]. However, I also need to get the value of the unchecked checkboxes since this form is dynamically being built and the number of checkboxes may vary as well as change state from checked to unchecked and vice versa.

<form method='post' action=''> <tr>
    <td>Trouble Type</td>
    <td>
    <input type='checkbox' name='checkboxvar[]' value='Option One'>1<br>
    <input type='checkbox' name='checkboxvar[]' value='Option Two'>2<br>
    <input type='checkbox' name='checkboxvar[]' value='Option Three'>3
    </td> </tr> </table> <input type='submit' class='buttons'> </form>

<?php 
if (isset($_POST['checkboxvar'])) 
{
    print_r($_POST['checkboxvar']); 
}
?>

I've seen some suggestions using !isset($_POST[ ]) but I'm not certain on how that would work or if that is even a solution for the problem.

Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire