Codeigniter - Set_value when checked

I use the form validation library for forms in Codeigniter. When I use set_value for input fields to refill, it works fine, but how to do it on the checkboxes? If they are verified, I want them to still be checked if form errors return.

How?

This does not work:

<?php $js = 'onClick="shipping(this.form)"'; echo form_checkbox('fillShipping', 'check', set_value('fillShipping'), $js); ?> 
+4
source share
2 answers

In your view, try using something like this:

 <?php $js = 'onClick="shipping(this.form)"'; echo form_checkbox('fillShipping','check', set_checkbox('fillShipping','check'), $js);?> 
+3
source

There is a special function for this.

 <input type="checkbox" name="mycheck" value="1" <?php echo set_checkbox('mycheck', '1'); ?> /> 
+1
source

Source: https://habr.com/ru/post/1446686/


All Articles