form_checkbox([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]])
Parameters: |
|
---|---|
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);
Please login to continue.