I have created new field CCK "Duties." Type: text, Widget type: text area.
When I enter any text in this field when I create a material, drupal gives out a mistake: " Duties: illegal value".
How to me to create an ordinary working field for input of the text?
CCK 6.x-2.0-rc4, Drupal 6.3.
Many thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jshuster@drupal.org’s picture

Title: text area not work » Illegal value in text field; field's array is being changed
Version: 6.x-2.0-rc4 » 6.x-2.2

This still appears to be happening in 6.x-2.2. In my case, it's a text field with a set of allowed values; when saving the node from a non-administrator account, the field is rejected with the message: (fieldname): Illegal value.

Instrumenting text.module at the point where this error is generated (in text_field()), $item['value'] is the first letter of the value that was selected.

So, I displayed the value of the field in one of my modules' hook_nodeapi(), with this result:

  • op prepare: the field is structured correctly: $node->myfield[0]['value'] = the value selected
  • op validate: the field has been changed to this: $node->myfield['value'] (no 0 element to the array)

So I inserted code in the validate op to fix the field to its proper structure, and checked it again at presave:

  • op presave: the field has been changed back to $node->myfield['value']

Apparently, when the field's content is processed by text.module, it expects one more layer to the array structure, which is why it only uses the first character of the string.

Another clue: this only happens for ordinary authenticated users. Editing and saving the field works correctly in my admin account, and I verified that in an admin account, the field's array structure is not being changed to $node->myfield['value'].

I can force correct behavior by fixing the field structure in both the validate and presave steps in nodeapi, but that's a workaround.

I couldn't figure out how to track down where the field array structure is being corrupted, but I hope there's enough clues here to help someone who knows this code far better than I do.

Thanks --

mikejoconnor’s picture

FileSize
808 bytes

I'm running into a similar issue with a text field. It seems that this is caused when you are using a key|value pair, with a single checkbox. In my case I'm using 0 and 1. 1 is being typed as a boolean rather than an int. which causes the array_key_exists function to fail, and generates an validation failure.

warning: array_key_exists(): The first argument should be either a string or an integer in /Applications/MAMP/htdocs/register/modules/acquia/cck/modules/text/text.module on line 156.
Enhanced Listing: illegal value.
warning: array_key_exists(): The first argument should be either a string or an integer in /Applications/MAMP/htdocs/register/modules/acquia/cck/modules/text/text.module on line 156.

I've attached a patch that "fixes" the problem. I say fixes loosely because it simply casts the boolean to an integer.

mikejoconnor’s picture

FileSize
808 bytes

I'm running into a similar issue with a text field. It seems that this is caused when you are using a key|value pair, with a single checkbox. In my case I'm using 0 and 1. 1 is being typed as a boolean rather than an int. which causes the array_key_exists function to fail, and generates an validation failure.

warning: array_key_exists(): The first argument should be either a string or an integer in /Applications/MAMP/htdocs/register/modules/acquia/cck/modules/text/text.module on line 156.
Enhanced Listing: illegal value.
warning: array_key_exists(): The first argument should be either a string or an integer in /Applications/MAMP/htdocs/register/modules/acquia/cck/modules/text/text.module on line 156.

I've attached a patch that "fixes" the problem. I say fixes loosely because it simply casts the boolean to an integer.

fmarocha’s picture

Same here. I also get "illegal value" error, but only for the fields I choose Filtered text (user selects input format). The error doesn't happen with Plain text.

Any ideas?

remoran’s picture

Having to define a value for a text field is, IMHO, ridiculous. I am trying to build a form and I set up a give field to be plain text. When I type in, in this case, "bill for the firstname field, the db tells me it's an illegal value. What is going on here? I build databases and I don't have to deal this the extra bit of ageta in getting something done. Is there a clear and concise table articulating what the acceptable values are for the field types in Drupal because at this point in time, it's a total loss. .

kayakjim’s picture

Encountering the same problem with a text field using the text widget, entering a decimal value (e.g. 2.5) generates the "illegal value" message.

This did work previously.

jjoseph’s picture

I am also having the same problems, however I am working with cck select other text fields. I tried the patch however it did not work. Any ideas?

drupalsteve’s picture

I'm also receiving these "illegal value" errors.

pwaterz’s picture

I was experiencing the same problem as well. I am using a check box with a single on off field. My unchecked value was the number zero. After reading post #3 I went and changed the unchecked value to the word 'OFF' and the problem went away. But what makes it even more odd is that I went and changed it back to zero again and it worked fine....

jpl-2’s picture

This problem still exists in content 6.x-2.8. After several hours debugging I found steps to reproduce and narrowed it down to function optionwidgets_form2data.

Steps to reproduce:

1. Create a content type with a text field using optionwidgets_onoff widget (i.e. checkbox), in allowed values enter

off|
on|some label

2. Edit a node and set value to "on" for that field. Save the node.
3. Now alter your node edit form via drupal_form_alter hook, setting #access = FALSE for that field.
4. Edit a node and try saving it. You will get an "illegal value" error and "warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer" array_key_exists() during validation, both from text.module.

Analysis:

The content of $items in optionwidgets_form2data depends on whether we are processing a posted value or a default value (due to #access == FALSE):
1. If we are processing a posted value, and the checkbox is unchecked, $items will be array(0 => 0).
2. If we are processing a posted value, and the checkbox is checked, $items will be array(0 => 'on').
3. If we are processing a default value and the node field is unchecked, $items will be array(0 => FALSE).
4. If we are processing a default value and the node field is checked, $items will be array(0 => TRUE).

While I'm not sure where the difference comes from exactly and whether it could be avoided, the current code in optionwidgets_form2data does not account for cases 3 and 4. Therefore, I'm attaching a patch for the optionwidgets.module, which is less ugly and should cause fewer side effects than the patch from comment #3.

jpl-2’s picture

Scratch that patch, I think that the one proposed in comment #4 on http://drupal.org/node/716408 is even closer to the heart of the issue.

spgd01’s picture

Version: 6.x-2.2 » 6.x-2.9

Had same problem here. Couldn't add text to a text field. Also couldn't use default text either. I flushed all cache and all seams to work now.

j0rd’s picture

I'm noticing same problem as well with 'optionwidgets_buttons' and 'optionwidgets_form2data' as mentioned in #10

roderik’s picture

@jpl / #10: agreed, #716408 is closer to the heart of the issue you describe. See new patch at #716408-19: Single on/off checkbox: hook_form_alter() with ['#access'] = FALSE changes 'On' value to TRUE.

That should fix the problems reported in #2 / #3 / #9 / #10.

@j0rd: I tested but cannot reproduce things for other widgets and I don't understand the descriptions from other people. Now that I've delved into this anyway... Can you tell me the steps to reproduce your problem?

j0rd’s picture

@roderik, it's been a while and I can not recall unfortunately.

There are many widgets in Drupal (core / contrib) that continue to have issues with #access = FALSE.

I've compiled a small list in the description of one of my modules:
http://drupal.org/project/i18n_hide_sync