Tagged: checkbox save
August 27, 2013 at 11:58 am #2629
Hey all! I’ve set up checkboxes for days of the week in my metabox. But it only saves the selections if contiguous boxes, including the first one, are checked. So if I check:
Sa:[X] Su:[X] M:[X] T:[X] W:[X] Th:[ } F:[ ]
…it works, but if I do this:
Sa:[ ] Su:[X] M:[X] T:[X] W:[X] Th:[ } F:[ ]
Sa:[X] Su:[ ] M:[X] T:[X] W:[X] Th:[ } F:[ ]
…then after I save the post, all checkboxes are empty.
I used the exact code as per the example to add these boxes, only adding a div around the display of the box and title (php start and end tags removed here for display purposes only, and div not included since the code tag seems to delete it!):
$items = array('Sa', 'Su', 'M', 'Tu', 'W', 'Th', 'F');
while ($mb->have_fields('open_days', count($items))):
$item = $items[$mb->get_the_index()];
<input type="checkbox" name="the_name(); ?>" value=""the_checkbox_state($item); ?>/>
In a word… HELP!
AdamAugust 27, 2013 at 12:52 pm #2632
Additional info: I enabled the default example “checkbox-spec.php”, just to see if it worked or if those checkboxes had the same problem.
So it doesn’t appear to be my code. DB trouble? What else can i look into?August 27, 2013 at 3:24 pm #2633
Using the other checkbox-creation method (the “foreach” loop instead of the “while” loop) causes the checkboxes to reload properly in the backend.
The question is… why? Dimas, any chance you can modify the documentation to prevent future coders being tripped up by this? There’s no indication in the sample doc as to why one or the other would work differently.
At any rate, though – many thanks for a great resource!September 3, 2013 at 12:00 pm #2635
Not so crazy!
My options looked like this:
<option value="AK"the_select_state('Alaska'); ?>>Alaska
…and the_select_state (literally a select “State” in this case) differed from the value. I made them the exact same thing and it works fine.
You must be logged in to reply to this topic.