1

I would like to implement a custom redirect for anonymous users that try to access a form built with FAPI. user_is_logged_in is used in access callback to provide true or false.

However, I couldn't find documentation on how to hook into access callback functionality e.g. what happens when it returns FALSE? Now it automatically redirects to default user login page but I need change this.

1

4 Answers 4

0

Try the Rules module and generate a new rule for the form page being viewed by the anonymous users, to redirect to the page as you wish.

1
  • Hi! Thanks, this is the most obvious way and perhaps easiest too. At the moment I'm looking for more developer oriented solution (just to get my hands dirty and not belittle you proposal :) ) Commented Feb 18, 2015 at 8:41
0

You can make the page available for all users, also anonymous, and in the page callback redirect the anonymous user to your custom page.

1
  • Hi! Same goes here as above. I need to dig into the system to see what goes and where. But I'll report here what happened. Commented Feb 18, 2015 at 8:44
0

I think you can also try hook_init. Try this one, may be it'll work.

function mymodule_init() {
  global $user;
  // Getting path
  $path = url($_GET['q'], array('absolute' => true));
  // Redirect from the path
  if ($path == "http://localhost/sitename/node/1") {
    // Check anonymous user
    if ($user->uid == 0) {
      // Redirect to path
      drupal_goto("http://localhost/sitename/node/2");
    }
  }
}
1
  • Hi! Thanks, I tried similar but seems like other related modules don't support this idea as is since there is 3rd module that handles parts of login (didn't know this on forehand). But his is way forward :) Commented Feb 18, 2015 at 8:43
0

For now I just used user_is_logged_in() in page callback to get desired functionality.

It shows a login button on page if function returns false and by clicking it user is redirected to 3rd party site and back. Otherwise it shows content which is in this case a custom form.

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.