public function check_box()
{
return _class('html')->check_box('input_name', ['k1' => 'key1', 'k2' => 'key2']);
}
public function check_box($name = '', $value = '', $selected = '', $add_str = '', $extra = [])
{
if (is_array($name)) {
$extra = (array) $extra + $name;
$name = $extra['name'];
}
if ( ! is_array($extra)) {
$extra = [];
}
$extra['name'] = strlen($name) ? $name : (strlen($extra['name']) ? $extra['name'] : 'checkbox');
$extra['value'] = strlen($value) ? $value : (strlen($extra['value']) ? $extra['value'] : '1');
$selected = isset($extra['selected']) ? $extra['selected'] : $selected;
if (isset($extra['checked'])) {
$selected = $extra['checked'];
}
$extra['checked'] = $selected ? 'checked' : null;
$extra['id'] = ($extra['force_id'] ?: $extra['id']) ?: ($this->AUTO_ASSIGN_IDS ? __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__] : null);
$extra['desc'] = isset($extra['desc']) ? $extra['desc'] : ucfirst(str_replace('_', '', $extra['name']));
if ($extra['no_desc']) {
$extra['desc'] = '';
}
$extra['class'] = trim($extra['class'] . ' ' . $extra['class_add']);
$add_str = $extra['add_str'] ? $extra['add_str'] : $add_str;
$translate = $extra['translate'] ? $extra['translate'] : $translate;
$label_extra = $extra['label_extra'];
$def_label_class = $this->CLASS_LABEL_CHECKBOX . ' ' . $this->CLASS_LABEL_CHECKBOX_INLINE;
$label_extra['class'] = isset($label_extra['class']) ? $label_extra['class'] : (isset($extra['class_label_checkbox']) ? $extra['class_label_checkbox'] : $def_label_class);
if ($extra['class_add_label_checkbox']) {
$label_extra['class'] .= ' ' . $extra['class_add_label_checkbox'];
}
if ($selected) {
$label_extra['class'] .= ' ' . $this->CLASS_LABEL_CHECKBOX_SELECTED;
}
$body = [];
if ($extra['outer_label']) {
$body[] = '<label class="outer-label">' . $extra['outer_label'] . '</label>';
}
$extra['type'] = 'checkbox';
$body[] = '<label' . _attrs($label_extra, ['id', 'class', 'style']) . '>'
. '<input' . _attrs($extra, ['type', 'name', 'id', 'value', 'checked', 'class', 'style', 'disabled', 'required']) . ($add_str ? ' ' . $add_str : '')
. '> <span>' . ($translate ? t($extra['desc']) : $extra['desc']) . '</span>' // Please do not remove whitespace before :)
. '</label>';
return implode(PHP_EOL, $body);
}