Hi guys,

I need some help with the following:

I use Rules' action "Populate a CCK field" and I need to use PHP to "Specify the fields value with PHP code":

this means this particular node reference cck field is multi-valued and therefore the returned array has an undefined number of rows and depends on the user choice.

I use following code to achieve this
($values is an array containing the Node ID's the user has chosen)
($lastKey is a variable containing the last reference in $values)

return array(
 for ($i=0; $i<$lastKey; $i++) { 
   $i => array('nid' => $values[$i]),
 );
  }

I get the following error:

"Parse error: parse error, expecting `')'' in C:\xampp\mysite\sites\default\modules\rules\rules\modules\php.rules.inc(107) : eval()'d code on line 39"

Can someone help? This should be a small tweak... Thanks!

Comments

BillyMG’s picture

Uh, I think this is equivalent to what you're trying to do... It's kind of hard to tell from your code.

$arr = array();
for ($i = 0; $i < $lastKey; $i++) {
  $arr[$i] = array('nid' => $values[$i]);
}
return $arr;
klausi’s picture

Component: Forms Support » Rules Engine

Does not look to be rules_forms related.

mitchell’s picture

@mitkoru: any update on this?

drupov’s picture

@opensanta:

I think the solution is in #1. I tried to return an array with an for loop in it. Correct would be to run the for loop first and save it in a variable which to return.

mitchell’s picture

Status: Active » Fixed

>> I think the solution is in #1.

See also: Array Tokens.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.