2

I am having an error:

{"form_errors":{"field_category][und":"An illegal choice has been detected. Please contact the site administrator."}}

Field category is a taxonomy field attached to a node. I'm trying to create a node via web services and unable to create taxonomy field. I have also match post array by doing print_r($obj) on node form validate:

PHP Array:

[field_category] => Array(
  [und] => Array(
    [0] => Array(
      [tid] => 6246
    )
  )
)

JSON conversion:

"field_category": {
  "und": [
    {
      "tid":6246
    }
  ]
}

However, in response having an error, the same problem with the other taxonomy field. What I am doing wrong with it.

1
  • I have seen that error when trying to work with tids that don't exist. Have you confirmed the tid in question is in the database? Commented May 1, 2015 at 20:42

3 Answers 3

1

I was having the same issue. After reading this I was able to figure out the problem by doing a dsm($_POST) on hook_node_update() and inspecting the array and figuring out what it expects.

In my case my array looked like this:

'field_term_subtype[und]' => '166',

In your case it would be:

{
    "title": "your title",
    "type": "page",
    "field_category": {
        "und": 6246
    }
}
0

You should be able to create a node using a POST request.

For the node fields, you can use something like:

$node_data = http_build_query(
  array(    
    'type' => 'page',
    'title' => 'This node was created via the API.',
    'field_category[und][0][tid]' => 6246,
  )
);

[...]

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $node_data);

[...]

See also: https://drupal.stackexchange.com/a/72758/7153

1
  • No that is not working, even though I have also change it to "field_category":{ "und":"6243" } But now getting sql violation error
    – MSK
    Commented Jul 19, 2014 at 10:24
0

Try the following Json format to create node having taxonomy filed

{
    "title": "your title",
    "type": "page",
    "field_category": {
        "und": "termname"
    }
}
7
  • getting same error An illegal choice has been detected. Please contact the site administrator
    – MSK
    Commented Jul 19, 2014 at 11:13
  • Yes it quiet long I wont be able to post it here. In short having an sql error PDOException: SQLSTATE[42000]:
    – MSK
    Commented Jul 20, 2014 at 6:49
  • in field_sql_storage.module line: 451
    – MSK
    Commented Jul 20, 2014 at 6:49
  • I have also tried { "field_category":{ "und":"6243" } }
    – MSK
    Commented Jul 20, 2014 at 6:51
  • @MSK I've posted an answer to the similar question. That works. I don't know what's going on in your scenario Commented Jul 20, 2014 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.