Skip Navigation

[Resolved] If all selections are removed from a checkbox it does not save

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a checkboxes group custom field that allows me to select multiple values. I am displaying these checkboxes in a CRED form. If I check some values, then save, the checked values are stored correctly. Then if I edit the post again and uncheck all the checkboxes, the change is not saved correctly.

Solution: Update to the latest version of CRED, use unique values for each option, and save 0 to the database when nothing is checked.

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 23 replies, has 2 voices.

Last updated by lindsayH 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#577739

Okay thanks, I was confusing editing on the front end with editing in wp-admin. I also thought it might be related to data-dependent fields, but after a bit more discussion with the team, I have been informed that this is a bug in CRED that will be resolved in CRED 1.9.3. When all items are unchecked and saved, the CRED form shows them as all checked. We don't have an erratum post available but if a patch becomes available before the full release, I will let you know as soon as possible. Sorry for the inconvenience with this!

#588098

CRED 1.9.3 has been released, and includes a fix for the checkboxes issue you have experienced. Please install the latest version and let me know if you are still unable to save checkbox modifications.

#589277

Still seems to be a problem, if I remove all checks it doesn't save.

#589527

Hi, is it okay for me to update all Toolset plugins on staging? I see that CRED 1.9.2.1 is currently installed and I would like to test with 1.9.3, as well as the latest updates to Views and Types.

#590365

Yes, you can update anything on staging.

Thank you for your continued help.

#590404
Screen Shot 2017-11-16 at 6.33.50 PM.png

Hi Lindsay,
It seems to be working when the modifications we discussed earlier are implemented. Here's what I did in my first test:
- ?page_id=176 is essentially unusable with all the content and CRED forms, so I added a limit of 2 posts to the View shown here temporarily while testing. If you're testing with the same user I recommend doing the same 🙂
- I modified the Accommodations checkboxes field in the post field editor to save "0" to the database when nothing is checked
- I modified each option in the Accommodations field to save a unique value - they were previously all set to save "1"
- I edited the B**s Reach Supplier in the wp-admin area and checked all the Accommodation options, then saved.
- I visited ?page_id=176 and used the CRED form on the front-end of the site to uncheck all the options for Accommodations and saved the B**s Reach Supplier post.
- I reloaded the ?page_id=176, and now no Accommodations options are selected for B**s Reach. I confirmed in the backend that no Accommodation options are selected for this Supplier.

Is there a specific case that is failing for you? I'll be glad to check if you can point it out. Thanks!

#590643

Oh apologies, I'd forgotten I'd attached each post to one author.

Yes, I concur that changing the Save option to just 'When unchecked, save 0 to the database' then it seems to work. I don't even have to change each option in the Accommodations field to save a unique value - I returned them all to '1' and it seems OK.

Is this OK or can you for see any other issue if I just do this? Thank you.

Also, just an afterthought. Won't this make my db very large - I have a lot of these categories and any one supplier would normally only pick one or two. Now when they save all the un-selected categories will get saved to the dB too won't they?

#590980

I think you should be fine with all the options saved as "1" and saving "0" when nothing is selected. Selected checkbox options are stored in the DB as a single postmeta field of serialized data, so while the size of the value of the postmeta field will grow, the number of postmeta fields will remain the same regardless of the number of checkboxes selected.

#591291

Thank you for the further explanation.