To re-create this bug:

1. Create a text-field with checkboxes widget.
2. In widget settings: Required: Yes, Number of values: unlimited, Allowed values list: put in a few values
3. Save the widget and then go back, edit the widget again, select some default values.
4. Write a little hook_form_alter to add ['#access'] = FALSE to the field.
5. When trying to save that field, you will get the error: "illegal value".

Expected behavior is that the field is saved with the default value. This bug does not exist for any other widget type as far as I can tell.

Comments

phayes’s picture

Note that this is a blocker for the follow issue in urlfill: #767060: Hide field breaks checkboxes

jrockowitz’s picture

I am not familiar enough with the inner workings of CCK to recommend a patch/fix.

I did apply the below work-around.

$field['#access'] = FALSE;
// Convert checkboxes (optionwidgets_buttons) to a multi select menu (optionwidgets_select).
if ($field['#type'] == 'optionwidgets_buttons') {
  $field['#type'] = 'optionwidgets_select';
}
masondib’s picture

I'm having a similar issue: getting the "illegal value" error message on a checkboxes, unlimited-value text field with ['#access'] = FALSE set via hook_form_alter.

In my case, the field is not required, and no default value is set so the field value should be null, but it looks like somehow it's being set to (integer) 1. Which, in turn, is making text.module trip up on a non-text, non-allowed value. Couldn't trace this back to the source, but hopefully this information will help someone else identify the culprit.

My workaround was to call unset($field) in hook_form_alter instead of setting #access to FALSE, which seems to be working, but I'm not sure if this is best practice.

Chris Gillis’s picture

I have the same issue. None of my checkboxes are selected, but if I set the field to #access = FALSE, I can no longer submit the form without seeing an Illegal values error. It seems to be getting the integer 1, instead of NULL.
I can confirm that the workaround in #2 works for me.

webadpro’s picture

I'm having the same problem. Anyone found a fix for this?

Solution #2 fixed it for me also, but this should get fixed.

babbage’s picture

Same issue. Most frustrating.

djschoone’s picture

had same isssue with onoff checkbox
workaround #765962-2: Cannot assign default values to checkboxes when #access is set to FALSE works for me

arhak’s picture