form_checkbox()

form_checkbox([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]])

Parameters:
  • $data (array) – Field attributes data
  • $value (string) – Field value
  • $checked (bool) – Whether to mark the checkbox as being checked
  • $extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string
Returns:

An HTML checkbox input tag

Return type:

string

Lets you generate a checkbox field. Simple example:

echo form_checkbox('newsletter', 'accept', TRUE);
// Would produce:  <input type="checkbox" name="newsletter" value="accept" checked="checked" />

The third parameter contains a boolean TRUE/FALSE to determine whether the box should be checked or not.

Similar to the other form functions in this helper, you can also pass an array of attributes to the function:

$data = array(
        'name'          => 'newsletter',
        'id'            => 'newsletter',
        'value'         => 'accept',
        'checked'       => TRUE,
        'style'         => 'margin:10px'
);

echo form_checkbox($data);
// Would produce: <input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" />

Also as with other functions, if you would like the tag to contain additional data like JavaScript, you can pass it as a string in the fourth parameter:

$js = 'onClick="some_function()"';
echo form_checkbox('newsletter', 'accept', TRUE, $js);

Or you can pass it as an array:

$js = array('onClick' => 'some_function();');
echo form_checkbox('newsletter', 'accept', TRUE, $js);
doc_CodeIgniter
2016-10-15 16:32:18
Comments
Leave a Comment

Please login to continue.