3

snapshot:1

I want to use a button to create a new article.

I write two rules to do the following work

snapshot 2 snapshot 2

snapshot 3 snapshot 3

The snapshot 2 creates a new content; the snapshot 3 fills the field of the content just created.

I can't fill the node reference field; how can i do that?

The button I put is on a different kind of content type.

I hope some body can help me fix this article.

2 Answers 2

2

I found how to fix my own problem

$node->field_YOURFIELD[LANGUAGE_NONE][0]['uid']=$userid;
$node->field_YOURFIELD[LANGUAGE_NONE][0]['nid']=$nid;
0

Perhaps you could have a PHP action like this:

$nid = arg(1); //Gets the nid from the url
$node = node_load($nid);
$node->field_YOURFIELD['und'][0]['target_id'] = 10; //nid of referenced node
node_save($node);

This works with the Entity References module. I don't know about the node reference module. It might be 'value' instead of 'target id'. You can use the Devel module to find out.

You'll need to enable the PHP module.

4
  • thx for answering, but i have a question,if i change the URL alias,the code "$nid = arg(1)" still can get the node id ?
    – cobenash
    Commented Jun 7, 2012 at 4:08
  • It works in D7 even with aliased nodes. Not sure about D6. You need to make sure the code is not firing on the home page otherwise you'll get an error.
    – Dave
    Commented Jun 7, 2012 at 21:36
  • Sorry, i have a PHP action and wrote the same code above.But the return value of arg(1) is 'AJAX' and the return value of arg(0) is 'system'. The corresponding url is "localhost/test2/node/35".Could u plz tell me where's problem?
    – cobenash
    Commented Jun 8, 2012 at 3:44
  • Thx!i fixed the problem
    – cobenash
    Commented Jun 8, 2012 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.