1

I am using hook_menu() to generate a series of MENU_CALLBACKS for processing data at various points in my sites operations. However, while these work for the admin, when trying to access the pages I get the following error message:

You are not authorized to access this page.

I am trying to get this so that the pages can be reached by all users (one is used for submitting a form and processing the results), the other is used for logging outgoing data. The code is as follows:

function modulename_menu() {
  $items = array();
   $items['data/update'] = array(
    'page callback' => 'dataupdate',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
   $items['onthewayout/forward'] = array(
    'page callback' => 'register_click',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}
  • I can't seem to recall any such message by Drupal, if there would be an access issue Drupal by default would generate a 403. What other modules do you use? Perhaps this comes from the page itself, not from the menu item access callback. – Wtower Sep 10 '14 at 14:13
2

I tested out the hook_menu in my local. The hook seems fine. Check if you have added an access denied code in the callback function

function commons_menu() {
  $items = array();
   $items['data/update'] = array(
    'page callback' => 'dataupdate',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
   $items['onthewayout/forward'] = array(
    'page callback' => 'register_click',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function dataupdate() {
  return drupal_set_message("First one is working");
}

function register_click() {
  return drupal_set_message("Second one is also working");
}

This returns a Access Denied to me even if access callback is true.

function register_click() {
  drupal_access_denied();
  exit;
}
0

You are missing the title key. According to the docs:

"title": Required. The untranslated title of the menu item.

  • The docs do say it's required, but nothing's actually enforced (i.e. it won't be causing a 403) – Clive Sep 10 '14 at 17:15

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.