lundi 8 octobre 2018

Checkbox post array is always empty

.html

<input type='checkbox' name='check_list[]' value='first'>First
<input type='checkbox' name='check_list[]' value='second'>Second
<input type='checkbox' name='check_list[]' value='third'>Third
<input type='checkbox' name='check_list[]' value='fourth'>Fourth

.php

if(!empty($_POST['check_list'])){
    foreach($_POST['check_list'] as $selected){
        echo $selected;
    }
}

I'm trying to get the check_list[] values, but it never executes the foreach because check_list[] is always empty even with all the checkboxes checked.

If i remove the IF condition i get an "undefined index check_list" i don't really know why.




Aucun commentaire:

Enregistrer un commentaire