phpdrupaldrupal-6drupal-hookshook-menu

Passing values to functions through URI (instead of the GET method)


I'm writing a Drupal 6 module that sends a user ID + a randomly generated string to a function through the URI. I'm using the menu hook:

function invites_menu() {    
  // ...    
  $items['invites/auth'] = array(
    'title' => 'Are you human?',
    'page callback' => 'invites_pageAuth',
    'access arguments' => array('access invites content'),
    'page arguments' => array(2),
    'type' => MENU_CALLBACK
  );
  // ...
}

I am new to Drupal, but as I understand it (and I could well be mistaken) this should pass two values to the callback function, which for testing purposes currently looks like this:

function invites_pageAuth($auth = NULL, $uid = NULL) {
  drupal_set_message("uid: $uid <br /> $auth");
}

The URL I use is 'invites/auth/RANDOMSTRING/USERID'. This seems to get the first value twice; both $auth and $uid contain 'RANDOMSTRING'.

Am I missing something really simple?
Thank you.


Solution

  • function invites_menu()
    {    
    ...    
        $items['invites/auth/%/%'] = array(
                'title' => 'Are you human?',
                'page callback' => 'invites_pageAuth',
                'access arguments' => array('access invites content'),
                'page arguments' => array(2, 3),
                'type' => MENU_CALLBACK
              );
        ...
    }
    

    Also you can use arg(3) as user object -> use %user instead % and you will get user object in your callback

    $items['invites/auth/%/%user']