I am trying to set the value for an existing Node Reference drop-down field in a content type via hook_form_alter as part of an AJAX call. The form needs to set values based on a selection, which is does correctly for dozens of fields, but I can't get or find the array structure to change/set the value for a Node Reference field. I've looked around and tried every permutation I can find, including dozens of guesses at what the array structure should look like without any success. Any help would be appreciated.
1 Answer
With Clive's help, I was able to figure out the array structure I needed. To set the node ID for a Node Reference field (References Module) in hook_form_alter, this structure worked for me:
$form['field_name'][LANGUAGE_NONE]['#value'][0] = {node id}
array(array('nid' => 1))
(single value field) orarray(array('nid' => 1), array('nid' => 2))
(multi value).