Html radios
html_radios {html_radios} is a custom function that creates an html radio button 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 radio button list (defaults to 'radio button') |
| values | Yes, unless using options attribute | An array of values for radio buttons |
| output | Yes, unless using options attribute | An array of output for radio buttons |
| selected | No | The selected radio button 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 radio button item |
| assign | No | Assign radio button 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 "Tplixradio buttons" |
| radioButtonClasses | No | If you wana add css classes to radio button than use this like form-control |
| escape | No | Escape the output / content (values are always escaped) (defaults to true) |
- Required attributes are
valuesandoutput, unless you useoptionsinstead. - 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_radios name='id' options=$cust_radiobuttons selected=$customer_id assign="radioButtonsList" labelClasses="" radioButtonClasses="" separator='<br>'}
{$radioButtonsList}
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="radioButtonsList", the output will be stored in the variable {$radioButtonsList}.
You can then use {$radioButtonsList} anywhere you need to display the assigned output.The above template will output:
<input type="radio" name="id[]" class="" value="1000">Joe Schmoe<br>
<input type="radio" name="id[]" class="" value="1001" checked="">Jack Smith<br>
<input type="radio" name="id[]" class="" value="1002">Jane Johnson<br>
<input type="radio" name="id[]" class="" value="1003">Charlie Brown<br>{html_radios name='id' values=$cust_ids output=$cust_names selected=$customer_id labels=true radioButtonClasses="form-control" labelClasses="tplixradiobuttons" separator='<br>'}
When the parameter
labels is set to true, the value of labelClasses will be applied to each element associated with the radio buttons.
Example:
labels=true labelClasses="tplixradiobuttons"
In this case, each radio button’s label will include the class tplixradio buttons.The above template will output:
<label class="tplixradiobuttons"><input type="radio" name="id[]" class="form-control" value="1000">Joe Schmoe</label><br>
<label class="tplixradiobuttons"><input type="radio" name="id[]" class="form-control" value="1001" checked="">Jack Smith</label><br>
<label class="tplixradiobuttons"><input type="radio" name="id[]" class="form-control" value="1002">Jane Johnson</label><br>
<label class="tplixradiobuttons"><input type="radio" name="id[]" class="form-control" value="1003">Charlie Brown</label><br>