Skip to content

Instantly share code, notes, and snippets.

@marcosrocha85
Last active September 24, 2018 18:48
Show Gist options
  • Save marcosrocha85/aee2bef5b3cb0d923b056f1d290bfc35 to your computer and use it in GitHub Desktop.
Save marcosrocha85/aee2bef5b3cb0d923b056f1d290bfc35 to your computer and use it in GitHub Desktop.
CodeIgniter form_pretty_checkbox
/**
* Pretty Checkbox Field for CodeIgniter and pretty-checkbox-vue from @hamed-ehtesham
*
* @access public
* @param mixed
* @param string
* @param bool
* @param string
* @return string
*/
if (!function_exists('form_pretty_checkbox'))
{
function form_pretty_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
{
$defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
if (is_array($data) AND array_key_exists('checked', $data))
{
$checked = $data['checked'];
if ($checked == FALSE)
{
unset($data['checked']);
}
else
{
$data['checked'] = 'checked';
}
}
if ($checked == TRUE)
{
$defaults['checked'] = 'checked';
}
else
{
unset($defaults['checked']);
}
return "<p-check "._parse_form_attributes($data, $defaults).">".$extra."</p-check>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment