Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Remove the brackets from the field name in your call to <code>set_checkbox()</code>:</p> <pre><code>&lt;input type="checkbox" name="protocols[]" value="online" &lt;?php echo set_checkbox('protocols', 'online');?&gt; /&gt; &lt;input type="checkbox" name="protocols[]" value="network" &lt;?php echo set_checkbox('protocols', 'network');?&gt; /&gt; &lt;input type="checkbox" name="protocols[]" value="splitscreen" &lt;?php echo set_checkbox('protocols', 'splitscreen');?&gt; /&gt; </code></pre> <p>The form validation library will take care of checking the box or not, but it responds to the <code>$_POST</code> array only, so you'll have to use the third parameter to get the inputs checked by default:</p> <blockquote> <h3>set_checkbox()</h3> <p>Permits you to display a checkbox in the state it was submitted. The first parameter must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).</p> </blockquote> <p>Not a great explanation, but here's an example. First get your values from the comma separated string:</p> <blockquote> <p>The database values return as a comma separated string (online,splitscreen). </p> </blockquote> <pre><code>// Something like this $values = explode(',', $my_data); // Now it's an array </code></pre> <p>Then check if each checkbox's value is in that array:</p> <pre><code>&lt;?php echo set_checkbox( 'protocols', 'splitscreen', in_array('splitscreen', $values) // TRUE checks the box, FALSE does not );?&gt; </code></pre> <p>I'd do this in a loop for convenience reasons if nothing else. It's also worth looking at <code>form_checkbox()</code> which will make this a good deal easier.</p> <p>See user guide for details: <a href="http://ellislab.com/codeigniter/user_guide/helpers/form_helper.html" rel="nofollow">http://ellislab.com/codeigniter/user_guide/helpers/form_helper.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload