mercredi 4 décembre 2019

Keep Checkbox State on Match Array Keys After Submit

I want to keep the checkbox state checked after I submit the form. I've made this code

For show all checkbox options.

$arr_array = array();
foreach( explode( ',', 'red,blue,green,black' ) as $k => $v )
{
    $arr_array[] = array(
        "name" => trim($v),
        "selected" => ''
    );
}

And in template I created an If statement to check if value "selected=1" then checked else unchecked.

Also I created this function to check which options was checked

foreach( $arr_array as $key => $value ){
     $keys = array_keys($_POST['colors']);
}

How to keep the state of checkbox after submit the form?




Aucun commentaire:

Enregistrer un commentaire