# Checkbox

The Checkbox field may be used to offer a single check option, or a group of multi-check options.

# Arguments

Name Type
Default
Description
type string checkbox Value identifying the field type.
options array Array of key pair values representing the individual check boxes. They key represents the ID of the checkbox, the value is the text displayed next to the checkbox.
default string/int/array See Default Argument below.

# Default Argument

When using a single checkbox, the default argument accepts a string/int/bool representing with 0/false or 1/true. When using multi-checkbox, the default argument accepts an array of key pair values. They key represents the id of the checkbox, the value either a 0/false or 1/true value.

# Build Config

Build a Custom Configuration →
Changes you make to this form will be reflected in the generated code.
Field visibility requirements.

Redux::set_field( 'OPT_NAME', 'SECTION_ID', array(
    'type' => 'checkbox'
) );

# Example Config

# Single Checkbox

Redux::addField( 'OPT_NAME', 'SECTION_ID', array(
    'id'       => 'opt_checkbox',
    'type'     => 'checkbox',
    'title'    => __('Checkbox Option', 'redux-framework-demo'), 
    'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
    'desc'     => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
    'default'  => '1'// 1 = on | 0 = off
) );

# Multi Checkbox

Redux::addField( 'OPT_NAME', 'SECTION_ID', array(
    'id'       => 'opt_multi_checkbox',
    'type'     => 'checkbox',
    'title'    => __('Multi Checkbox Option', 'redux-framework-demo'), 
    'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
    'desc'     => __('This is the description field, again good for additional info.', 'redux-framework-demo'),

    //Must provide key => value pairs for multi checkbox options
    'options'  => array(
        '1' => 'Opt 1',
        '2' => 'Opt 2',
        '3' => 'Opt 3'
    ),

    //See how default has changed? you also don't need to specify opts that are 0.
    'default' => array(
        '1' => '1', 
        '2' => '0', 
        '3' => '0'
    )
) );

# Example Usage

This example in based on the example usage provided above. Be sure to change $redux_demo to the value you specified in your opt_name argument.

# Single checkbox

$global $redux_demo;

echo 'Checkbox value: ' . $redux_demo['opt_checkbox'];

# Multi checkbox

$global $redux_demo;

echo 'First checkbox value: '  . $redux_demo['opt_checkbox']['1'];
echo 'Second checkbox value: ' . $redux_demo['opt_checkbox']['2'];
echo 'Third checkbox value: '  . $redux_demo['opt_checkbox']['3'];