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
#574200
Field Group.png
Edit CRED form.png
After Save CRED.png

When I try to save a form, if ALL checkboxes selections are removed it does not save.

If I change a selection (as long as one of the check boxes remains selected) then it will save correctly.

So on the Edit CRED form.png I switched from Beer Glasses to Martini. And I removed the Public Liability Insurance so nothing in that cred_show_group selected at all.

The After Save Cred.png show that the Beer Glasses remained deselected and Martini selected.

But the Public Liability remained selected (I'd saved deselected). It's like one item HAS to remain selected in a group.

Example Code on the CRED form and Field Group image attached.

[cred_show_group if="(STR($(supplier-category)) = REGEX('148'))" mode="fade-slide"]

	<div class="cred-group cred-group-magicians">
		<div class="cred-header"><h4>Magicians</h4></div>
		<div class="cred-field cred-field-magicians-options">
			<label class="cred-label">
Options You Provide
</label>
			[cred_field field='magician-options' post='wedding-supplier' value='' urlparam='']
		</div>
	</div>

[/cred_show_group]
#574277

Hi, are the values for each checkbox in a single group different? If not, please make sure to use different values for each checkbox in a group.

If the values are already different, then let's try to eliminate other possible issues:

- Please temporarily remove any cred_show_group tags from this edit form and try again:

[cred_show_group if="(STR($(supplier-category)) = REGEX('148'))" mode="fade-slide"]

- Please temporarily remove any conditional display code from these custom fields, and try again.

- Disable plugins except for Toolset and activate a default theme, then try again.

Please let me know the results of these tests and we can go from there.

#574283

To eliminate two options:
Values for each checkbox are different.
I'm not using the Conditional display button for the fields in the group.

I will have to test on my staging site, I'm testing emails from the CRED form currently so don't want to mess this up. Will do in a few days.

#574600

Understood, I'll mark this ticket as pending an update from you. No need to reply right now, we can pick up again when you're ready to continue.

#575127

OK - I disabled all plugins (except Toolset ones) and switched the theme. Same issue.

I removed all the cred_show_groups from the CRED edit form. This again made no difference.

Also, JFYI I switched to your Toolset Starter theme (twice, on a clean second set up too). Both times I ended up with a:
Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.

My site seemed to grow exponentially too - in fact the first time, I reached my quota all of a sudden and after increasing it reached it again. After removing the staging site in its entirety and trying for a second time it happened again. I found that as soon as I deleted the theme from my back-end all returned to normal and I could activate and use Twenty Seventeen for testing purposes fine.

#575193

Okay thanks. Please choose "When unchecked, save 0 to the database" in the options for this field. Then update the post several times to test again. If this does not resolve the problem, I'll probably need to create a clone of your site to see what's happening.

#575202

OK, I think I did test for this previously, though I may not have then 'update the post several times to test again' as you requested

I am happy to do this first and then give you access to my staging site but currently I'm now doing another test for my email issue, hopefully by the middle of next week I can send you and update and login credentials for you to look at if an issue still occurs.

Many thanks.

#575221

Understood, I will stand by for your update.

#576482

I have set the 'Hair' field to "When unchecked, save 0 to the database" and tested many times. There is still a problem if trying to remove all selections. There is a difference now though. If I remove all options, save from the front end and return, both options now remain checked. Before saving 0 to the db, only the original option de-selected remained selected after the save.

If selecting 1+ option(s) and changing that selection all works fine, both before and after setting 0 to the db.

If you mark the next reply as private I can send you login credentials for my staging site.

#576677

Private reply fields enabled.

#577108
hair-options.png
magician-options.png

Hi, both the Hair checkboxes and both the Magician checkboxes store the same value. Please see the attached screenshot. You can see the checkbox "value" is 1, which may be causing the problem you mentioned. Can you update these values to be unique per field group, resave all Hair or Magician posts to import the new values, and try again?

#577418
Hair Options.png

Hi, I changed Hair and only had this attached to a Post. But no change.

See image attached...

Many thanks.

(PS I'm not being notified via email for some reason, so sorry for the delay).

#577464
Screen Shot 2017-10-09 at 4.35.11 PM.png

Hi, I changed Hair and only had this attached to a Post. But no change.
Hi, I'm not sure what you mean by "only had this attached to a Post", can you elaborate?

I just logged in and bulk-edited all Suppliers posts by going to Suppliers > All Items, checking all the checkboxes, and using the Bulk Edit option. I didn't actually make any changes to the posts, I just updated them. This is required because we have changed the values that the checkboxes store (or don't store) in the database, and you need to apply the new values to all the posts.

Then, I edited Supplier #3327, and modified the Hair selections. As you can see now, both checkboxes are unchecked. Can you take a look and confirm the Hair checkboxes are behaving as expected now? If not, please show me what's going wrong.

#577570

Hi, what I meant by 'only had this attached to a Post', I'd only got Hair added, not any other field groups. Sorry if not clear.

I see no difference. I updated all the Supplier's posts as you outlined.

Are you using my staging 2 and the update CRED form from the front end?

If you make the next reply private I can give you the URL of the form and the login credentials of the supplier I'm testing on.

Many thanks, Lindsay

#577644

Yes, please share that info here. Private reply fields are enabled.