-1
I have several dynamic checkbox that are listed as follows:
<?php foreach($configs as $config): ?>
<?php echo utf8_encode($config['description'])?><input style="margin-left:10px;" type="checkbox" name="in_active[<?php echo $config['config']?>]" <?php if($config['in_active'] == true){echo 'checked';}?>/> <?php if(isset($config['value'])){echo "<input type='number' class='form-control' name='value[".$config['config']."]' step='0.01' min='0' value='".$config['value']."'>";}?> <br>
<?php endforeach?>
This data is sent to a controller, where I have an array called "in_active", which receives the checkbox.
$data = array();
if(isset($_POST)){
$data['in_active'] = $_POST['in_active'];
$data['value'] = $_POST['value'];
$updateConfig = new Configuration();
$updateConfig->updateAllConfigs($data);
}
This data is sent to a model, where I do a foreach to update the db.
$in_active = $data['in_active'];
foreach($in_active as $config => $val):
if($val){
$val = true;
}else{
$val = false;
}
$sql = $this->db->prepare("update configurations
set
in_active = :in_active
where config = :config
");
$sql->bindValue(':config',$config);
$sql->bindValue(':in_active',$val);
$sql->execute();
endforeach;
But that way I can only update, when they are unchecked, when I uncheck no, I know that you realize that checkboxes only send something when they are checked. So, how do I get around this? How do I update db when unchecking chexbox?