If I create a multi-value checkbox field, I cannot set this field with XML-RPC. Even simply loading the node and saving it with no changes fails. Here are the steps to reproduce:

  1. Install CCK and Services modules
  2. Create a new CCK content-type called "checkbox_test", and edit it
  3. Add a field with these settings:
    Name
    test_checkboxes
    Type
    Integer Check Boxes/radio buttons

    And press Create Field.

  4. Choose these settings:
    Multiple Values
    Checked
    Allowed values
    1
    2
    3

    And press Save field settings.

  5. Create a new node of this type, with these settings:
    Title
    Test
    test_checkboxes
    check 1, 2, and 3
  6. Load the node with XML-RPC, using the node.load command
  7. Attempt to save the node back exactly as you loaded it.

I get this error: Illegal value for test_checkboxes.
I expect it to simply save the node back with no changes

If I make changes to the node, I also get an error, unless there are no selections for test_checkboxes.

If I use a type of "Integer Text Box" or "Integer Select List" and repeat the test as above, it works as expected.

Comments

scottgifford’s picture

From my debugging so far, the problem appears to be in optionwidgets_widget when doing "process form values". The format that comes in from XML-RPC appears to be different from a Web form, and the values are screwed up when it tries to convert them from the form to a native format.

pathfinderelite’s picture

I have a problem which I believe is related. 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 did some investigating, but I'm too unsure of my results to post them quite yet. If you have time scottgifford, try to use 4,5,6 (or any values other than 0 and 1)
to reproduce your results.

pathfinderelite’s picture

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

yched’s picture

@pathfinderelite : you issue looks unrelated - I opened a separate issue at #387494: Default value applied on checkboxes even when none defined and copied your findings over there

scottgifford’s picture

Status: Active » Closed (duplicate)

OK, I think the rest of this bug is a dup of Services bug http://drupal.org/node/374636; the data model for the Services interface is very tied to the UI, which is something that will hopefully be fixed in a future version. In the meantime I'll code up a custom XML-RPC interface to load and save my nodes.

greg.harvey’s picture

Title: Multi-value Checkbox fields break XML-RPC services » Multi-value Checkbox fields break drupal_execute()
Version: 5.x-1.10 » 6.x-2.x-dev
Priority: Normal » Critical
Status: Closed (duplicate) » Active

I've marked this up to the top of the D6 tree, but it seems from Scott's comments that this stands all the way to Drupal 5.x versions. I am experiencing the same issue - he was doing it through the Services module, but the Services module simply calls a drupal_execute, so in effect he's seeing exactly the same issue as me:

I have a module for importing data as part of a migration job from another platform to Drupal. One of the CCK fields on one of my content types is a multiple check-box. It is text, not required and has three possible values. I am "selecting" one of them like this (I created this data structure in $form_state after printing the node submit form results to screen to see what it should be):

  $form_state['values']['field_stockist_products'][0]['value'] = 'water';

However, this returns the error message Products stocked: illegal value. =(

The biggest issue, however, is that even if no value is supplied, it still throws the same error so it is currently impossible to drupal_execute a node form with a multiple check-box CCK field on it. Hence marking this up to critical.

Look forward to hearing what you think. =)

adam640kb’s picture

Version: 6.x-2.x-dev » 6.x-2.4

I too am experiencing this issue with the current release. When attempting to use drupal_execute() to save a form, the presence of an optional checkbox field (string or integer, null or populated) causes an "Illegal Value" error.

markus_petrux’s picture

Category: bug » support
Priority: Critical » Normal
Status: Active » Fixed

You're not using the correct format of the field in the form state values array.

If you have a list of allowed values like this:

array(
  'coke' => t('Coke'),
  'water' => t('Water'),
  'wine' => t('Wine'),
);

Then try this:

$form_state['values']['field_stockist_products']['value']['water'] = 'water';

In case of doubt, visit the node edit form and view the HTML source.

ximo’s picture

If you want the field to be empty, that is with no checkboxes selected, try this:

$form_state['values']['field_stockist_products']['value'][''] = '';

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jenlampton’s picture

Project: Content Construction Kit (CCK) » Drupal core
Version: 6.x-2.4 » 6.15
Component: optionwidgets.module » forms system
Status: Closed (fixed) » Active

I've tried running drupal_execute with both

$form_state['values']['buttons']['something'] = 1;

(this his how it looks when the actual FAPI form is submitted) as well as

$form_state['values']['buttons']['something'] = 'something';

and in both cases my 'buttons' values are excluded from $form_state['values'] in the submit handler.

I have noticed that in the FAPI form $form['buttons']['#tree'] = TRUE is declared, but I'm not sure that has anything to do with my missing multiple-value checkboxes.

The values are correct in $form_state['clicked_button']['#post']['buttons'].

It looks like the $form_state['values'] are correct until drupal_process_form() is called.

hm. ok, I must be doing something terribly wrong because $form_state['values'] is supposed to be reset here... I will compare more closely to my other forms that work with drupal_execute. :/

jenlampton’s picture

Project: Drupal core » Content Construction Kit (CCK)
Version: 6.15 » 6.x-2.4
Component: forms system » optionwidgets.module
Status: Active » Closed (fixed)

putting things back as they were pending further investigation.

stillfinder’s picture

Issue tags: +checkboxes, +services, +xmlrpc

Hello!
I have some problem with checkboxes and xmlrpc via services module. I write some application in C# and can't to send checkbox data to services. Maybe someone know in what format data must be sended?

With Date field I sending like this and all work perfect:

private static void AddArrayDateToNode(string fieldname, DateTime dt, XmlRpcStruct node)
        {
            XmlRpcStruct sMainDate = new XmlRpcStruct();
            XmlRpcStruct sDate = new XmlRpcStruct();
            sDate["year"] = dt.Year.ToString();
            sDate["month"] = dt.Month.ToString();
            sDate["day"] = dt.Day.ToString();
            sMainDate["value"] = sDate;
            object[] oDate = new object[] { sMainDate };
            node[fieldname] = oDate;
        }

So we have an array:

-		["field_exclusive_from"]	{object[1]}	
		Key	"field_exclusive_from"	object {string}
-		Value	{object[1]}	object {object[]}
-		[0]	Count = 1	object {CookComputing.XmlRpc.XmlRpcStruct}
-		["value"]	{CookComputing.XmlRpc.XmlRpcStruct}	
		Key	"value"	object {string}
-		Value	Count = 3	object {CookComputing.XmlRpc.XmlRpcStruct}
-		["month"]	"6"	
		Key	"month"	object {string}
		Value	"6"	object {string}
-		["year"]	"2011"	
		Key	"year"	object {string}
		Value	"2011"	object {string}
-		["day"]	"30"	
		Key	"day"	object {string}
		Value	"30"	object {string}

Thanks to all for any help.

stillfinder’s picture

Hi! I found solution for problems with cck fields (checkboxes and date time picker) and xml-rpc services node.save function

datetime cck field you need to send in following format:
[field_date] => Array
(
[0] => Array
(
[value] => Array
(
[year] => 2014
[month] => 7
[day] => 7
)
)
)

and CheckBoxes in this format:
[field_b_material] => Array
(
[value] => Array
(
[1991] => 1991
[1985] => 1985
)
)

Where 1991 is ID of taxonomy term.

If someone interested for C# code I can to send it.

rustemkaymaz’s picture

Hi,
can you send C# code to me...

BGood’s picture

dunmcl, can you please send C# code to me too? Thanks