Closed (fixed)
Project:
Services
Version:
7.x-3.1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
23 Apr 2012 at 20:01 UTC
Updated:
10 Nov 2016 at 09:47 UTC
Jump to comment: Most recent
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
Comment #1
DUG1138 commentedAnyone?
Comment #2
j_cimb_barker commentedReplace:
'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).
Comment #3
DUG1138 commentedHa! Nice! Thank you so much.
This worked perfectly.
Comment #4
marcingy commentedComment #5
s.daniel commentedFor 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?
Comment #6
DUG1138 commentedNo, 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?
Comment #7
s.daniel commentedI 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.
Comment #8
DUG1138 commentedI'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.
Comment #9
s.daniel commentedOK 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ührerscheinfield_aa_berufsfelder is a taxonomy field set to show a select list. url-encoded:
field_aa_berufsfelder[und][]:3Here once with jquery sending the data as json and once urlencoded:
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.
Comment #9.0
s.daniel commentedexpanded question details
Comment #10
revnoah commented#2 did it for me, nice and simple. Thanks!
Comment #11
irishgringo commentedjust 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!!!!
Comment #12
hubobbb commented#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.