src/template/Html.php
public static function checkbox($name, $checked = false, $options = [])
    {
        $options['checked'] = (boolean)$checked;
        $value = array_key_exists('value', $options) ? $options['value'] : '1';
        if (isset($options['uncheck'])) {
            // add a hidden field so that if the checkbox is not selected, it still submits a value
            $hidden = static::hiddenInput($name, $options['uncheck']);
            unset($options['uncheck']);
        } else {
            $hidden = '';
        }
        if (isset($options['label'])) {
            $label = $options['label'];
            $labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : [];
            unset($options['label'], $options['labelOptions']);
            $content = static::label(static::input('checkbox', $name, $value, $options) . ' ' . $label, null, $labelOptions);
            return $hidden . $content;
        } else {
            return $hidden . static::input('checkbox', $name, $value, $options);
        }
    }
public static function checkbox($name, $checked = false, $options = [])
    {
        $options['checked'] = (boolean)$checked;
        $value = array_key_exists('value', $options) ? $options['value'] : '1';
        if (isset($options['uncheck'])) {
            // add a hidden field so that if the checkbox is not selected, it still submits a value
            $hidden = static::hiddenInput($name, $options['uncheck']);
            unset($options['uncheck']);
        } else {
            $hidden = '';
        }
        if (isset($options['label'])) {
            $label = $options['label'];
            $labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : [];
            unset($options['label'], $options['labelOptions']);
            $content = static::label(static::input('checkbox', $name, $value, $options) . ' ' . $label, null, $labelOptions);
            return $hidden . $content;
        } else {
            return $hidden . static::input('checkbox', $name, $value, $options);
        }
    }
public static function checkbox ( $ name , $ checked = false , $ options = [ ] ) { $ options [ 'checked' ] = ( boolean ) $ checked ; $ value = array_key_exists ( 'value' , $ options ) ? $ options [ 'value' ] : '1' ; if ( isset ( $ options [ 'uncheck' ] ) ) { // add a hidden field so that if the checkbox is not selected, it still submits a value $ hidden = static :: hiddenInput ( $ name , $ options [ 'uncheck' ] ) ; unset ( $ options [ 'uncheck' ] ) ; } else { $ hidden = '' ; } if ( isset ( $ options [ 'label' ] ) ) { $ label = $ options [ 'label' ] ; $ labelOptions = isset ( $ options [ 'labelOptions' ] ) ? $ options [ 'labelOptions' ] : [ ] ; unset ( $ options [ 'label' ] , $ options [ 'labelOptions' ] ) ; $ content = static :: label ( static :: input ( 'checkbox' , $ name , $ value , $ options ) . ' ' . $ label , null , $ labelOptions ) ; return $ hidden . $ content ; } else { return $ hidden . static :: input ( 'checkbox' , $ name , $ value , $ options ) ; } }
Generates a checkbox input.

@param string $name the name attribute.
@param boolean $checked whether the checkbox should be checked.
@param array $options the tag options in terms of name-value pairs. The following options are specially handled:

- uncheck: string, the value associated with the uncheck state of the checkbox. When this attribute
is present, a hidden input will be generated so that if the checkbox is not checked and is submitted,
the value of this attribute will still be submitted to the server via the hidden input.
- label: string, a label displayed next to the checkbox.  It will NOT be HTML-encoded. Therefore you can pass
in HTML code such as an image tag. If this is is coming from end users, you should {@see \rock\template\Html::encode()} it to prevent XSS attacks.
When this option is specified, the checkbox will be enclosed by a label tag.
- labelOptions: array, the HTML attributes for the label tag. Do not set this option unless you set the "label" option.

The rest of the options will be rendered as the attributes of the resulting checkbox tag. The values will
be HTML-encoded using {@see \rock\template\Html::encode()} . If a value is null, the corresponding attribute will not be rendered.
See {@see \rock\template\Html::renderTagAttributes()} for details on how attributes are being rendered.

@return string the generated checkbox tag
Generates a checkbox input .