0

I have a rule for returning users to finish creating a cck form. I need to 'Do' custom PHP code to redirect the user to editing/finishing their cck form (node limiter limits user to only one PPE content item). The following does not work:

function ppe_edit_user_login(&$edit, $account) {
  global $user;
  $nid = db_query('SELECT nid FROM {node} WHERE uid = :uid', array(':uid' => $user->uid))->fetchField();
  drupal_goto('node/' . $nid . '/edit');
}

What am I missing?

  • Can you verify that the function gets called, for example by having it print something then exit? – richardg May 24 '11 at 13:49
  • @richardg thanks for the suggestion. I added a phpinfo(). A message in the same Do gets set, but the function does not seem to get called. If I add phpinfo(); all by itself, it prints. If I strip the func and only have the mid three lines, I get white screen. – Tom May 24 '11 at 21:47
2

Here is the right code, or at least code that works:

$nid = db_result(db_query('SELECT nid FROM {node} WHERE uid = %d', [account:uid]));
$_REQUEST['destination'] ='node/' . $nid . '/edit';
  • this one is D6 code, the first was D7. But I think [account:uid] should be $user->uid. – nonsenz May 25 '11 at 18:37
  • "[account:uid]" is used in PHP code run inside a rule action, and it is replaced with the user ID of the currently logged in user. – kiamlaluno Sep 21 '11 at 12:52
1
function ppe_edit_user_login(&$edit, $account) {
  global $user;

  $nid = db_query('SELECT nid FROM {node} WHERE uid = :uid', array(':uid' => $user->uid))
    ->fetchField();

  drupal_goto("node/$nid/edit");
  exit;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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