sy4mil/Options-Framework — Issue #26: Undefined Index for checboxes
Author: zabestof
Created: 2012-02-02 18:31:07+00:00
State: open

Hi,

Just posted from your blog.

I have set up a checkbox, false by default. When I try to echo the result I get nothing. When I enable it and echo the result it displays 1. But when I disable it again and echo the result it displays: “Notice: Undefined index: slider_on_off”

With my old theme options (I think it was based on the KIA one) I had this code that was handling the checkbox value:

elseif($new_value == '' && $type == 'checkbox') { // Checkbox Save
update_option($id,'false');
}
elseif ($new_value == 'true' && $type == 'checkbox') { // Checkbox Save
update_option($id,'true');
}

and this for the checkbox itself:

case "checkbox":
$std = $value['std'];
$saved_std = get_option($value['id']);

$checked = '';

if(!empty($saved_std)) {
if($saved_std == 'true') {
$checked = 'checked="checked"';
}
else{
$checked = '';
}
}
elseif( $std == 'true') {
$checked = 'checked="checked"';
}
else {
$checked = '';
}
$output .= '';
break;

With this code every time I enabled/disabled the checkbox it displayed “true” or “false”.