Welcome Guest, Not a member yet? Register   Sign In
form_checkbox doesn't check the box when updating the DB
#1

Not sure how to explain this:
I use the form helper for most html input functions. I pull from the database and pre-populate the form to update information.

When I use the form_checkbox, if the option is set (0 for FALSE), when I check the box and click on update, it will not show the check in the box even though it updated the database on the next refresh.

I managed to get it working but not using form_checkbox (in this instance) helper function.

Here is the code:
<div class="form-group form-group-lg row"> 
                                    <?php $extra = array('class' => 'col-4 col-form-label col-form-label-md');
                                    echo form_label('Extra / Bonus Ball?''extra_ball_lb'$extra); ?>
                                    <div class="col-8" style="margin-top:10px;">
                                        <input type = "checkbox" name = "extra_ball" value = "1" <?php echo (!empty($lottery->extra_ball) ? 'checked' : ''); ?> /> 
                                        <?php //echo form_checkbox('extra_ball', '1', set_checkbox('extra_ball', '1', (!empty($lottery->extra_ball)))); ?>
                                    </div>
                                </div>

I commented out the form_checkbox since it does.

What's really strange, (on the same page), I have very similar code that works perfectly but I can't explain why this one works and the code above doesn't work? 
Here is a code that works on the same page:
<div class="form-group"> 
                            <?php $extra = array('class' => 'col-4 col-form-label col-form-label-sm');
                            echo form_label('Monday''day_monday_lb'$extra); 
                            echo form_checkbox('monday'set_value('monday''1'), set_checkbox('monday''1', (!empty($lottery->monday)))); 
                            echo form_label('Tuesday''day_tuesday_lb'$extra); 
                            echo form_checkbox('tuesday''1'set_checkbox('tuesday''1', (!empty($lottery->tuesday))));
                            echo form_label('Wednesday''day_wednesday_lb'$extra); 
                            echo form_checkbox('wednesday''1'set_checkbox('wednesday''1', (!empty($lottery->wednesday))));
                            echo form_label('Thursday''day_thursday_lb'$extra); 
                            echo form_checkbox('thursday''1'set_checkbox('thursday''1', (!empty($lottery->thursday))));
                            echo form_label('Friday''day_friday_lb'$extra); 
                            echo form_checkbox('friday''1'set_checkbox('friday''1', (!empty($lottery->friday))));
                            echo form_label('Saturday''day_saturday_lb'$extra); 
                            echo form_checkbox('saturday''1'set_checkbox('saturday''1', (!empty($lottery->saturday))));
                            echo form_label('Sunday''day_sunday_lb'$extra); 
                            echo form_checkbox('sunday''1'set_checkbox('sunday''1', (!empty($lottery->sunday)))); 
                            echo form_error('monday''<div class="bg-warning" style = "margin-top:10px; padding: 10px; text-align: center; color:#ffffff; font-size:16px;">''</div>'); ?>
                        </div>
Reply


Messages In This Thread
form_checkbox doesn't check the box when updating the DB - by metadatamedia - 01-02-2020, 07:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB