25 Jun 2018

Display the results of a checkbox field using Toolset Types in a PHP template

To display the results of a Toolset Types checkbox field, use the following in your PHP template:


$checkbox_value = types_render_field( "my_checkbox_field", array( "separator" => ", " ) );
echo $checkbox_value;

Taking it a step further, we can create conditionals based on values collected. In the following example I have four values:


$blacktown = types_render_field( "localities", array( "option" => "0" ) );
$carlingford = types_render_field( "localities", array( "option" => "1" ) );
$emerton = types_render_field( "localities", array( "option" => "2" ) );
$penrith = types_render_field( "localities", array( "option" => "3" ) );

if ($blacktown) {
// do something
};
if ($carlingford) {
// do something
};
if ($emerton) {
// do something
};
if ($penrith) {
// do something
};