mardi 4 août 2015

Get a checkbox value even if it is unchecked when checkbox is an array name

I need to submit all my checkboxes on my page. I've got the following code to display the checkboxes:

foreach($categories as $category){
    $cat_name = $category->name;
    $cat_name = htmlspecialchars_decode($cat_name);
    $list_name = $network_name.' '.$cat_name;
    if (in_array($list_name, $list_names)) {
        $checked = 'checked';
    }else{
        $checked = '';
    }
    $output .= '<input type="hidden" name="subscribe[]" value="0">';
    $output .= '<input type="checkbox" name="subscribe[]" value="'.$list_name.'" '.$checked.'>';
    $output .= $list_name;
    $output .= '<br>';
}

Now I'm trying to process these with a foreach loop:

foreach($_POST['subscribe'] as $value){
    echo "it has a value of".$value;
}

This will only show me the checkboxed boxes but I also want to get the value of the non-checked boxes. Is there a way to do this?




Aucun commentaire:

Enregistrer un commentaire