I have a form with other fields, I have a list of clients in a checkbox array. To get that list I use the database table-field and populate a list. HTML FORM
<? if($this->clientCount > 0){?> <? foreach($this->client as $valuec) {?> <input type="checkbox" name="banner_allowed1[]" value="<?=$valuec['company_id']?>" <?if($valuec['banner_allowed']==1){echo 'checked="checked"';}?> style="margin:auto; size:20px;"> <?=$valuec['title']?></label><br> <?}?> <?}?>
Now when I submit the form, I need to know which one are unselected, because the form loads with the value selected from the database. I need to update the database table field value to zero(0) for the unselected ones. I am finding a hard time with dynamic checkboxes to do a name value pair or get values of unselected checkboxes as post doesn’t send unselected checkbox values
MY submit page in POST, only getting checked checkbox values if(!empty($_POST['banner_allowed1'])){ foreach($_POST['banner_allowed1'] as $clientid1){ $update['userid'] = $uid; $update['banner_allowed'] = 1; $this->db->update('clientlist', $update, "id=$clientid1"); } } else { }
Advertisement
Answer
How i said in the comment you can use array_diff
for select only the value isn’t selected :
$dbarray = array('1','2','3','4'); $selectedarray = array('1','3'); $substract = array_diff($dbarray, $selectedarray); print_r($substract); //print 2,4