Welcome Guest, Not a member yet? Register   Sign In
form_checkbox with set_checkbox
#1
Brick 

Is it possible to use set_checkbox helper with form_checkbox function?
Reply
#2

This question was submitted a couple of years ago, but maybe my answer will benefit someone. I was working on a form and ended up with this solution:

Code:
$checkbox_data = [
  'name' => 'name',
  'value' => '1',
  'checked' => set_checkbox('name', '1') != '' ? true : false
];


Notice how "checked" is set. The set_checkbox method returns either ' checked="checked"' or an empty string. We can check it and set true or false. After that in view we can use this:

Code:
<?= form_checkbox(checkbox_data) ?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB