I'm trying to do this in PHP with cURL:

$node_data = array(
'title' => $title,
'type' => 'public_document',
'body[und][0][value]' => $body,
'field_some_text_field_data[und][0][value]' => $field_some_text_field_data,
'field_taxonomy_term_here[und][0][value]' => $help,
);

$node_data = http_build_query($node_data);

Does anyone know the proper syntax for assigning values to a node's taxonomy fields?

From examining the database directly, it would seem that the correct syntax would be like this:

'field_taxonomy_term_here[und][0][tid]' => $help,

However that only gets me "The requested URL returned error: 406"

Has anyone ever done this before?

Thank you,
Doug

Comments

DUG1138’s picture

Anyone?

j_cimb_barker’s picture

Replace:

'field_taxonomy_term_here[und][0][tid]' => $help,

With

'field_tags[und]' => 'MyTag'

Where MyTag is the name of your tag and tags is the name of the vocabulary list. (The tag should have been added to this already).

DUG1138’s picture

Ha! Nice! Thank you so much.

This worked perfectly.

marcingy’s picture

Status: Active » Closed (fixed)
s.daniel’s picture

For me this only works if the taxonomy field is set to freetagging.
Have you managed to add a node with a term attached that is selected from a list?

DUG1138’s picture

No, I don't think I have tried that. I'm very new at Drupal. Currently I'm trying to get this other similar issue sorted out:

http://drupal.org/node/1599326

Have you any experience with this that could help?

s.daniel’s picture

I have posted a link there that may or may not be helpfull. If you could share your code of node.js and node_edit.js I would be very grateful.

DUG1138’s picture

I'm afraid I have no node.js code to share.

I'm doing all of this in PHP; just trying to import a bunch of data from a PostgreSQL database to Drupal's database.

I need to be able to make associations (one-to-many) between Nodes. So I installed the "Entity Reference" module.

Now I'd like to be able to do a batch process that creates the Nodes from the PostgerSQL data and makes those associations. I've tried all the syntax that makes sense and waited for answers on this forum for weeks.

field_my_field[und][0][target_id] seems like it should work, but it doesn't.

s.daniel’s picture

OK never mind I've got it working. What I did was to print out $_POST and make a JSON String out of it. This only worked for me when previewing a node, not when submitting it. Then I took that json string and built a test with jQuery.ajax(). What could be interesting there for you is that jQuery translates sends the json string as url encoded by default wich is where you then can get the right syntax from.

field_stichworte is a taxonomy field with tagging. url-encoded: field_stichworte[und]:Führerschein
field_aa_berufsfelder is a taxonomy field set to show a select list. url-encoded: field_aa_berufsfelder[und][]:3

Here once with jquery sending the data as json and once urlencoded:

$(document).ready(function() {

var jsonObjects = {title:"my title",type:"arbeitsangebot",field_aa_berufsfelder:{und:["3"]},field_arbeitsbeschreibung:{und:[{value:"ab"}]},field_anforderungen:{und:[{value:"anf"}]},field_stichworte:{und:"F\u00fchrerschein"},field_arbeitsort:{und:[{name:"Von zu Hause aus",street:"Mystreet. 23",additional:"",postal_code:"76344",city:"Eggenstein",country:"de",locpick:{user_latitude:"49.080864",user_longitude:"8.392010"}}]},field_arbeitszeitraum:{und:[{show_todate:"1",value:{date:"2012\/06\/24",time:"12:15"},value2:{date:"2012\/06\/24",time:"22:15"},rrule:{FREQ:"WEEKLY",daily:{byday_radios:"INTERVAL",INTERVAL_child:"1"},weekly:{INTERVAL:"1"},monthly:{day_month:"BYMONTHDAY_BYMONTH",BYMONTHDAY_BYMONTH_child:{BYMONTHDAY:"1"},BYDAY_BYMONTH_child:{BYDAY_COUNT:"+1",BYDAY_DAY:"SU"}},yearly:{INTERVAL:"1",day_month:"BYMONTHDAY_BYMONTH",BYMONTHDAY_BYMONTH_child:{BYMONTHDAY:"1"},BYDAY_BYMONTH_child:{BYDAY_COUNT:"+1",BYDAY_DAY:"SU"}},range_of_repeat:"COUNT",count_child:"",until_child:{datetime:{date:""},tz:"Europe\/Paris",all_day:"1",granularity:"a:3:{i:0;s:4:\"year\";i:1;s:5:\"month\";i:2;s:3:\"day\";}"},exceptions:{EXDATE:[{datetime:{date:""},tz:"Europe\/Paris",all_day:"1",granularity:"a:3:{i:0;s:4:\"year\";i:1;s:5:\"month\";i:2;s:3:\"day\";}"}]},additions:{RDATE:[{datetime:{date:""},tz:"Europe\/Paris",all_day:"1",granularity:"a:3:{i:0;s:4:\"year\";i:1;s:5:\"month\";i:2;s:3:\"day\";}"}]}}}]},field_arbeitsdauer:{und:[{value:"10"}]},field_stundenlohn:{und:[{value:"10"}]},log:"send via ajax",path:{alias:""},comment:"2",name:"admin",date:"",status:"1"};

  $("#create-aa-json").click(function() {
    $.ajax({
      type : "POST",
      url : "http://mydomain.de/?q=drupalgap/node.json",
      mimeType: "application/json", 
      contentType: "application/json",
      data : JSON.stringify(jsonObjects),
    }).done(function( msg ) {
      alert( "Data Saved: " + msg );
    });
  });

  $("#create-aa-url").click(function() {
    $.ajax({
      type : "POST",
      url : "http://mydomain.de/?q=drupalgap/node.json",
      //dataType: "json",
      //mimeType: "application/json", 
      //contentType: "application/json",
      data : jsonObjects,
    }).done(function( msg ) {
      alert( "Data Saved: " + msg );
    });
  });


});

I ended up simply using json as when the data gets more complex urlencoded gets a little messy but both ways work.
Here is the file I was refering to: https://github.com/sDaniel/DrupalGap/blob/LocalMarket/drupalgap/services...

I don't use node reference but maybe the way described above will help you as well.

s.daniel’s picture

Issue summary: View changes

expanded question details

revnoah’s picture

Issue summary: View changes

#2 did it for me, nice and simple. Thanks!

irishgringo’s picture

just a note. I am posting nodes via services from my ANDROID and iPHONE apps. And I was having trouble submitting Tax Terms as well. I ended up using rules. It turned out to be a fairly simple solution, but I am still very interested in other techniques.

What I did was just submit ordinary TEXT fields. I used rules to update a REFERENCE field based on that field.

Two Tricks to consider...
1...
The Obvious EVENT that I started was...
Before Saving Content. This did not work probably because I was comparing data that had not been saved yet.

The EVENT that worked was...
After saving new content of type

2...
When doing a REFERENCE FIELD, based on a TAX vocabulary, there is a sneaky, barely viewable option...
switch to direct input mode

It will give you a drop down of your Vocabulary... It rocks!!!!

hubobbb’s picture

#2 works for me .Thank you .

But if the vac has the same term name ( with two or more tid ) ,is has trouble .eq . in school ,class one --Math ; class two -- Math .

Or, Only write a php function api for this situation whih MySQL language.