I have a problem to showing checked checkbox in form update,
my views:
<?php foreach($pertanyaan as $p) { ?>
<form action="<?= base_url('SAdmin/PertSurvei/edit/'.$p['id_pert']); ?>" method="post">
<div class="form-group row">
<label class="col-sm-4 col-form-label">Animals</label>
<div class="col-sm-8">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" name="animals[]" alt="Checkbox" value="Chicken" class="form-check-input" <?php if (in_array("Chicken", $p)) echo "checked";?>>
Chicken
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" name="animals[]" alt="Checkbox" value="Cow" class="form-check-input" <?php if (in_array("Cow", $p)) echo "checked";?>>
Cow
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" name="animals[]" alt="Checkbox" value="Pig" class="form-check-input" <?php if (in_array("Pig", $p)) echo "checked";?>>
Pig
</label>
</div>
</div>
</div>
</form>
<?php }?>
my controller:
public function edit($id_pert)
{
$data = array(
'id_pert' => $id_pert,
'pertanyaan' => $this->pertModel->detailPertanyaan($id_pert),
'pertanyaan' => $this->request->getVar('pertanyaan'),
'id_unit' => $this->request->getVar('id_unit'),
'animals' => implode(", ", ($this->request->getVar('animals'))),
'id_kat' => $this->request->getVar('id_kat')
);
$this->pertModel->editPertanyaan($data);
return redirect()->to(base_url('SAdmin/pertSurvei'));
}
im using modal bootstrap for form update. Does anyone know where the problem is? what should i do?
Aucun commentaire:
Enregistrer un commentaire