I not sure why this has been so hard to figure out,

I have a nodereferance field that the user sets when they create a node: "field_campaign"

I usually use contemplate to find the variables of a node I can use and using that I found that I can print the name of the node reference field using:

print $node->field_campaign[$node->language][0]['safe_value'];

So using Rules, When the node is created Im trying to add the value of this field to a variable

$campaign = $node->field_campaign[$node->language][0]['safe_value'];

Except that when I do that I get an error:

Notice: Undefined index: safe_value in eval() (line 6 of mysite/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code).

Im not sure why I cant assign this variable, any ideas?

Comments

TheOldGuy223’s picture

Additionally, Contemplate states I can use the following to return the same value:

print $node->field_campaign[$node->language][0]['node']->title

when when I try to assign this value to a variable I get 2 errors this time

$campaign = $node->field_campaign[$node->language][0]['node']->title;

Notice: Undefined index: node in eval() (line 6 of mysite/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code).
Notice: Trying to get property of non-object in eval() (line 6 of mysite/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code).

faqing’s picture

Try this:

$campaign = $node->field_campaign['und'][0]['node']->title;
print $campaign;

You can check this:
http://drupal.org/node/1601226

faqing’s picture

Try this:

$campaign = $node->field_campaign['und'][0]['node']->title;
print $campaign;

You can check this:
http://drupal.org/node/1601226