How to use check a checkbox in CodeIgniter?
<p>I have checkbox which is created as below in CI:</p>

<pre><code>echo form_checkbox(array(
    'name' =&gt; 'active',
    'id' =&gt; 'active',
    'value' =&gt; '1'
));
</code></pre>

<p>I also have other fields such as Name which have a required field validation applied. So, when I leave Name as blank and tick the <code>active</code> checkbox, then it shows error for name. But it removes the check on active checkbox. I want to keep the active checkbox as checked. </p>

<p>I know about a <code>set_checkbox</code> method in CI, but not sure how to use this in the above. In case of <code>form_input</code> we simply use <code>set_value</code> and all is ok. But with <code>set_checkbox</code> it returns full string <code>checked="checked"</code>. So when I use the <code>set_checkbox</code> and <code>form_checkbox</code> as combined as below, then it doesn't work. </p>

<pre><code>echo form_checkbox(array(
    'name' =&gt; 'active',
    'id' =&gt; 'active',
    'value' =&gt; '1',
    'checked' =&gt; set_checkbox('active', '1')
));
</code></pre>

<p>Any idea how to fix this?</p>