1

EDIT:

14:38 PM Amsterdam :P

Nice to see that good people help !...

What I trying to do:

This is the whole prototype code.

function oleg_menu() {


    $items=array();
    $items['user/%user/pgacademy/tests'] = array(
        'title' => 'OLEG',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('oleg_nameform',1),
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
    );
    return $items;
}


function oleg_nameform($form, &$form_state,$accoundID) {
     $form=array();
     dpm($accauntID);
     return $form;
}         

The page even doesn't appear... Can someone explain me why it fails,or what could be the problem ? Oleg

2
  • Actually what you are trying to achieve. could you please elaborate more? Aug 31, 2012 at 10:23
  • 1
    using $items['user/%user/foo/bar] should work.. You must clear the caches everytime.
    – AjitS
    Aug 31, 2012 at 10:23

1 Answer 1

1

What indrock says in the comments is right, you should be using a placeholder like %user.

But you'll also need to pass the argument through to the form callback like so:

function my_module_menu() {
  $items['user/%user/foo/bar'] = array(
    'title' => 'My Title',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_module_nameform', 1),
    'access callback' =>array('user_is_logged_in'), 
    'type' => MENU_CALLBACK,
  );
  return $items;
}

The signature for my_module_nameform() would be:

function my_module_nameform($form, &$form_state, $account)

user_is_logged_in() doesn't accept any parameters so there's no need for the access arguments. Again as indrock says, clear the caches whenever you make a change to the hook implementation.

6
  • I have edited the post ... :) take a new look... Aug 31, 2012 at 12:42
  • Did you clear Drupal's caches after making the change? And by 'not appear' do you mean that a new tab doesn't appear on the user account?
    – Clive
    Aug 31, 2012 at 12:43
  • Hi Clive, I flushed the cache..I am doing it every time. The tab is there...But it displays something different,from the module "Panels". Still...if I do global $user and $user->uid it works very fine for a single user :(.... I am really confused Aug 31, 2012 at 12:50
  • Ah, it sounds like panels is doing a number on the page. I can't help with that I'm afraid, I've never used it. The code above is 100% definitely the right way to do it; it might be worth asking a question to the effect of "why does panels stop this code working?"
    – Clive
    Aug 31, 2012 at 14:38
  • Also its not the user id but rather the fully loaded user object that will passed through to your form function...could that be causing a problem? If you don't want that to be the case, just change the menu path to user/%/foo/bar. That will pass the account id rather than the user object
    – Clive
    Aug 31, 2012 at 14:40

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.