This question already has an answer here:
- Re-populate checkbox if it fails in validation in an edit form in Codeigniter 5 answers
So far I know how to repopulate the form input and checkbox
It looks like that:
value="<?= set_value('rank') ?>" for input
and
<?= set_checkbox('is_default', '1'); ?> for checkbox
The problem is, how about in the edit form:
The input value is sofar ok:
value="<?= set_value('rank',$customer_group[0]['rank']); ?>"
but I can't repopulate the checkbox
<?php if ($customer_group[0]['is_default'] == "1") echo "checked"; set_checkbox('is_default', '1'); ?>
The checkbox will check even I have not check it in the edit => fail to validate in the form, thanks for helping
Update:
Is it correct if change to :
<?php
if(isset($_POST['is_default']) || $customer_group[0]['is_default'] == "1"){
echo "checked";
}
set_checkbox('is_default', '1');
?>