CCK requires a little voodoo to alter values with a hook_form_alter(). You need to implement a special type: after_build
, so put this code in a custom.module
:
//Declare the callback for after_build for page node form
function custom_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'page_node_form) {
$form['#after_build'][] = 'custom_after_build';
}
}
function custom_after_build($form, &$form_state) {
//Set my node ref to 5
$form['field_node']['nid']['nid']['#value'][0] = 5;
//you can set more than one using
$form['field_node']['nid']['nid']['#value'][2] = 6;
//have a look at the form after after_build
dsm($form);
return $form;
}
I adapted a previous answer of mine, but I have to admin that node reference is even more confusing ;)