Html checkboxes

html_checkboxes {html_checkboxes} is a custom function that creates an html checkbox group with provided data. It takes care of which item(s) are selected by default as well.

Attributes

Attribute Name Required Description
name No Name of checkbox list (defaults to 'checkbox')
values Yes, unless using options attribute An array of values for checkbox buttons
output Yes, unless using options attribute An array of output for checkbox buttons
selected No The selected checkbox element(s) as a string or array
options Yes, unless using values and output An associative array of values and output
separator No String of text to separate each checkbox item
assign No Assign checkbox tags to an array instead of output
labels No Add <label>-tags to the output (defaults to true)
label_ids No Add id-attributes to <label> and <input> to the output (defaults to false)
labelClasses No If you wana add css classes to labels than use this like your custome class name "TplixCheckboxes"
checkBoxClasses No If you wana add css classes to checkbox than use this like form-control
escape No Escape the output / content (values are always escaped) (defaults to true)
  • Required attributes are values and output, unless you use options instead.
  • All output is XHTML compliant.
  • All parameters that are not in the list above are printed as name/value-pairs inside each of the created <input>-tags.

Examples

<?php
$tplix->assign('cust_ids', array(1000,1001,1002,1003));
$tplix->assign('cust_names', array(
                                'Joe Schmoe',
                                'Jack Smith',
                                'Jane Johnson',
                                'Charlie Brown')
                              );
$tplix->assign('customer_id', 1001);

Where the template is:

{html_checkboxes name='id' options=$cust_checkboxes selected=$customer_id assign="CheckBoxesList" labelClasses="" checkBoxClasses="" separator='<br>'}
{$CheckBoxesList}
In the above example, the output is assigned to a variable instead of being returned directly. The variable name is defined by the assign parameter. For example, if you used assign="CheckBoxesList", the output will be stored in the variable {$CheckBoxesList}. You can then use {$CheckBoxesList} anywhere you need to display the assigned output.

The above template will output:

<input type="checkbox" name="id[]" class="" value="1000">Joe Schmoe<br>
<input type="checkbox" name="id[]" class="" value="1001" checked="">Jack Smith<br>
<input type="checkbox" name="id[]" class="" value="1002">Jane Johnson<br>
<input type="checkbox" name="id[]" class="" value="1003">Charlie Brown<br>
{html_checkboxes name='id' values=$cust_ids output=$cust_names selected=$customer_id labels=true checkBoxClasses="form-control"  labelClasses="tplixCheckboxes" separator='<br>'}
When the parameter labels is set to true, the value of labelClasses will be applied to each element associated with the checkboxes. Example: labels=true labelClasses="tplixCheckboxes" In this case, each checkbox’s label will include the class tplixCheckboxes.

The above template will output:

<label class="tplixCheckboxes"><input type="checkbox" name="id[]" class="form-control" value="1000">Joe Schmoe</label><br>
<label class="tplixCheckboxes"><input type="checkbox" name="id[]" class="form-control" value="1001" checked="">Jack Smith</label><br>
<label class="tplixCheckboxes"><input type="checkbox" name="id[]" class="form-control" value="1002">Jane Johnson</label><br>
<label class="tplixCheckboxes"><input type="checkbox" name="id[]" class="form-control" value="1003">Charlie Brown</label><br>
Was this article helpful?