CCK: Default Value for a Node Reference Field

farzan - September 17, 2007 - 11:37

Hello,

I have some problems with setting a default value for a CCK field;

- I have a content type named "Part"
- This content type has a CCK field named "Manufacturer" which its data should refer to another node of type "manufacturer".
- I want to use a PHP snippet to set the default value for this field. I use this snippet:

first I tried to return the node id but it didn't work, field remains empty:

return array(0 => array('value' => 19));

then i tried to return the node alias:

return array(0 => array('value' => 'wheel'));

it didn't work either.

Do you have any idea how can I set a default value for a "Node Reference" field?
Note that i can set a default value for a simple text field or such, but same way doesn't work for Node References.

Thank you in advance.

Only a year late, but here is solution.

welzie - September 11, 2008 - 19:51

This is what worked for me with drupal 5.x and cck 5.x-1.7.

return array(0 => array('nid' => 13 ));

Only difference is that I have 'nid' instead of 'value'.

Responding in hopes of helping someone else.

replacing 'value' with 'nid'

seanmclucas - October 31, 2008 - 00:56

replacing 'value' with 'nid' doesn't seem to work either.

So how do I figure out the key name?

shunting - November 4, 2008 - 05:16

'value', 'nid', whatever?

and why 0=> .... ???

Maybe it's me, but this is feeling like a complicated thing that ought to be simple.

http://www.universalpantograph.com

 
 

Drupal is a registered trademark of Dries Buytaert.