简体   繁体   中英

Checkbox not returning value when not checked PHP Codeigniter

I have multiple checkboxes in the sampe page that have different values when checked or not. And these checkboxes also read values from database. Here's some sample of my current code.

1. this one should returning 'Absent' if not checked

<label class="checkbox-inline" for="Chronic_skin">
    <?php echo form_checkbox('Chronic_skin', 'Present', $values->Chronic_skin ? 'checked' : null, 'id ="Chronic_skin"')?> <b>Chronic Skin Rash</b>
</label>

2. This one should returning 'Abnormal' if not checked

<label class="checkbox-inline" for="breath_sounds">
    <?php echo form_checkbox('breath_sounds', 'Normal', $values->breath_sounds? 'checked' : null, 'id ="breath_sounds"')?> <b>Breath Sounds</b>
</label>

3. And this one should returning 'No' if not checked

<label class="checkbox-inline" for="others">
    <?php echo form_checkbox('others', 'Yes', $values->others? 'checked' : null, 'id ="others"')?> <b>others</b>
</label>

The problem that I'm having now when i press submit button (post button) the unchecked checkboxes didnt return any value (I checked using print_r() command), but the checked checkboxes is showing the values. Any help will be very much appreciated. Thanks

That's a common behavior. You can either check with some list of checkboxes, either the checkbox was sent out to the user or not, or you can accompany each checkbox with hidden input

<?php echo form_hidden('others_checkbox', '1'); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM