Craziness! Checkboxes not saved depending on which are checked

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

Tagged: 

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2629

    cosmocanuck
    Participant

    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); ?>/>

    endwhile;

    In a word… HELP!

    Thanks!
    Adam

    #2632

    cosmocanuck
    Participant

    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?

    #2633

    cosmocanuck
    Participant

    Solved… here:

    http://wordpress.stackexchange.com/questions/74263/wpalchemy-checkboxes-not-saving

    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!

    #2635

    cosmocanuck
    Participant

    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.