Craziness! Checkboxes not saved depending on which are checked

Home Forums WPAlchemy Craziness! Checkboxes not saved depending on which are checked


This topic contains 3 replies, has 1 voice, and was last updated by  cosmocanuck 1 year, 12 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #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:[ ]

    or this:

    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!




    Additional info: I enabled the default example “checkbox-spec.php”, just to see if it worked or if those checkboxes had the same problem.

    They do.

    So it doesn’t appear to be my code. DB trouble? What else can i look into?



    Solved… here:

    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!



    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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.