Skip Navigation

[Resolved] Checkbox: This value can't be zero

This support ticket is created 4 years, 7 months 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by fredericG-2 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1575743
value-cant-be-zero.png

I am trying to import data from a Drupal site using the plugin FG Drupal to WordPress.
Data are well imported.
But on the screen Toolset > Edit Post Field Group, for a checkbox field, I get this error (see the attached image).
In Drupal, the value "0" is possible for a checkbox value.
The problem is that the value "0" is not allowed in Toolset. So the WordPress site is not working.

Do you know why the value "0" is not allowed in Toolset?
Do you have a way to solve this issue?

For information, I'm the developer of the plugin FG Drupal to WordPress, and I don't see what I can do in my plugin.
The only solution I see is to allow the value "0" in the checkbox values, like in Drupal.
Does this make sense?

#1577169

Hi Frederic,

Thank you for contacting us and I'd be happy to assist.

The value '0' is not allowed in that field, so that it is easily distinguishable from "not set" or "empty" cases. Besides, since a checkbox can only have two states, i.e. checked or unchecked, I can't think of a case where saving '0' for the checked state value will be useful.

Note: you can save '0' for the unchecked state, through the "When unchecked, save 0 to the database" option.
( example screenshot: hidden link )

If Drupal allows saving '0' for a checked state value as well, a possible workaround can be to include a rule in the plugin to convert '0' to '1', for checkboxes type fields, while importing.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1577587

Thank you for your answer.
Unfortunately it doesn't solve the issue.
The checkboxes values I have in the Drupal database are a group of checkboxes starting at 0: 0, 1, 2, 3, ....
I can't just replace 0 by 1.

I agree that it is better to not use 0 as the checkbox value.
But why is it forbidden? Drupal allows it. And this is a problem for the sites migrated from Drupal.

#1579617

Hi Frederic,

Thank you for waiting while I performed some research.

It turns out that support for "0" as a checked state value was removed, due to some conflicts while using these fields in search filters in Views. Naturally, it won't be possible for us to remove that validation rule, just for the users with data imported from Drupal.

Unfortunately, the only way to make this work is to include some special code in the plugin to manipulate these checkbox type custom field definitions and the related metadata, either before the import or after it has been imported.
( i.e. detect the exact position of '0' which needs to be changed in that data and then replace it with a different number )

Notes: The Toolset Types field information is saved in the "options" table in WordPress, with key "wpcf-fields", in a serialized format.

You can also use the "types_get_fields()" function to retrieve all field definitions, as well.

I hope this makes sense and please let us know if you need any further assistance around the Toolset side of things.

regards,
Waqar

#1582745

Thank you for these informations.
You can close the ticket.