0

I am redirecting my users with the following code:

drupal_goto("event/registration/failed",
    array(
      'query' => array('nid'=>$submission->nid, 'sid'=>$submission->sid),
    )
);

On the target page I am executing the following function:

function _event_registration_failed($nid, $sid){
  dsm($_REQUEST);

  drupal_set_message("TESTING NID: {$nid}");
  drupal_set_message("TESTING SID: {$sid}");
}

My the variables in the drupal_set_message calls do not have any data. But, the $_REQUEST object above has the data I expected.

Is there a correct way to access argument passed with drupal_goto or is it correct to use the $_REQUEST object array?

1

Query arguments are available in $_GET. Drupal doesn't handle those query arguments for your menu callback; the only query argument Drupal automatically handles is $_GET['q'], which is the path for the requested page.

By default, $_REQUEST contains the contents of $_GET, $_POST and $_COOKIE. Drupal uses $_GET for the requested page path, and I would rather use $_GET also in this case, just to avoid possible conflicts.

In your case, those query arguments are accessible with $_GET['nid'], and $_GET['sid'].

If you define the menu handler with code similar to the following one, then your menu callback gets those values as arguments.

function event_menu() {
  $items["event/registration/failed/%/%"] = array(
    // …
    'page callback' => '_event_registration_failed',
    'page arguments' => array(3, 4),
  );

  return $items;
}

function _event_registration_failed($nid, $sid) {
  // …
}

You could get the node object, instead of the node ID, if you use the following code.

function event_menu() {
  $items["event/registration/failed/%node/%"] = array(
    // …
    'page callback' => '_event_registration_failed',
    'page arguments' => array(3, 4),
  );

  return $items;
}

function _event_registration_failed($node, $sid) {
  // …
}

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.