Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm trying to add nodes via a JSON feed. However, I'm having trouble setting the value of a select list field.

I have this at the moment:

$node->field_name[0]['nid'] = $drupal_array[trim($branch[0])]

Which when I output the node object at the end of execution works correctly but when it comes saving the node this individual field isn't saving at all.

Would anyone be able to tell me what I'm doing wrong. I can paste more code if you need it.

$drupal_array is used to convert the text input of $branch[0] to a numerical value.

This is the inserted value.

["field_name"]=>
    array(1) {
        [0]=>
            array(1) {
                ["nid"]=>
                    int(193)
           }
    }

This is the renderable array output of the same field.

["field_name"]=>
    array(1) {
        [0]=>
            array(1) {
                ["nid"]=>
                    string(3) "193"
            }
    }
share|improve this question
What's $drupal_array and $branch? And can you compare the $node array you create with the one taken from gui-created node? – Mołot Aug 22 at 13:36
How can I get the array of the gui-created node? – JonBubble Aug 22 at 13:42
$node = node_load($nid) and then dpr($node); if you have devel enabled. If not, var_dump(). – Mołot Aug 22 at 13:43
I've added these details to the question. Thanks for this! – JonBubble Aug 22 at 13:55
1  
What type of field is field_name? – jazzdrive3 Aug 22 at 13:59
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.