tammyhart / Reusable-Custom-WordPress-Meta-Boxes

177 stars 97 forks source link

Single Checkbox Won't Uncheck #34

Open INVSBL-HND opened 11 years ago

INVSBL-HND commented 11 years ago

Single checkbox meta fields won't "uncheck" and simply revert to the "checked" state upon saving the post.

I've rewritten the checkbox case to conditionally create a hidden input type with the same name as the checkbox input to allow for successful checking, unchecking, and rechecking of single checkboxes.

Below is my suggestion for replacing lines 62-66 of meta_box.php

// checkbox
case 'checkbox': 
echo '<input type="checkbox" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" ' . ($meta ? 'checked="checked"/><input type="hidden" name="' . esc_attr( $id ) . '"' : '').'/
<label for="' . esc_attr( $id ) . '">' . $desc . '</label>';
break;

Screen Shot 2013-02-13 at 11 40 27 AM

LinzardMac commented 9 years ago

I'e tried this method of fixing the error but it does not seem to work. I adjusted your variables to match my own and the HTML output is as expected but I stil get the undefined index and "headers already sent" errors