Un-hijacked from #374558: Multi-value Checkbox fields break drupal_execute() - Reported by pathfinderelite :

If I create a checkboxes field (using Check Boxes/radio buttons widget, then checking multiple values) on example_content_type with possible values 1,2,3, then create a node of type example_content_type w/o checking either 1,2 or 3, then submit the node, my '1' value somehow still gets checked. I didn't set the '1' box to be checked by default nor did I check it when creating the node, but somehow it still got checked before the node was inserted.

Whats really odd is that if I try a reproduce the problem using the possible values 4,5,6, I don't get the problem.

------

I figured out the source of my problem. When I first create a checkboxes field, it is actually a radio button field (because I haven't been able to select 'multiple values' yet. So, the default value is set to 'N/A' (which in the database is represented as an empty string). When I check 'multiple values' and add my possible values 1,2,3 and submit, the field changes from radio to checkboxes, but the default value is still an empty string. Now, when I edit the field, none of the checkboxes are defaulted to checked, but there is still a "hidden" default value, "" (the empty string).

Somehow, that empty string equates to a 0 or 1 when an instance of the field is being saved to the database.

The problem is that there is something like a race condition when changing from a radio buttons field to a checkboxes field. When you click 'multiple values' and save the field, the default value 'N/A' (the empty string) is saved to the database before the field is "transformed" into a checkboxes field (which should ideally have no boxes checked by default). I got around this problem by re-submitting the field settings again (so, after checking 'multiple values', submit, edit, and submit again). This process will remove the empty string from the database. However, if your possible values contain either 0 or 1, these will now be set as defaults in place of the empty string. So, now just uncheck those boxes from the defaults list, and submit.

So the process to successfully create a checkboxes field is
Create a 'Check boxes/radio buttons' field
Check 'Multiple values'
Submit
Edit the new field settings
Submit
Edit the new field settings and change the default values as desired
Submit

Comments

yched’s picture

Status: Active » Postponed (maintainer needs more info)

And actually I can't reproduce.
Are you creating the nodes through the regular edit form, or programmatically ?

pathfinderelite’s picture

I am creating them through the normal edit form.

pathfinderelite’s picture

Version: 6.x-2.x-dev » 5.x-1.10
karens’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

@pathfindererelite, you hijacked a D6 issue to report an unrelated D5 problem? Unfortunately, the time yched spent was wasted looking for the problem in the wrong version. The CCK maintainers don't have time to support D5 for anything other than critical bugs and this is something no one else has reported in the 2+ years that D5 has been in use, so probably no one will have more time than has already been spent on this problem.