I need to present the user login form from a callback function that I have registered in hook_menu(), at that specific URL. When the user logs in, I need to direct them back to that URL to present them with other options. Currently, I call:

if (!user_is_logged_in())

Of course, that takes them to the login page. I imagine I need to call drupal_get_form() to present the form from here, but how do I direct them back to this page after login?

1 Answer 1


You can render the user_login_block on your page. Once the user successfully log in, they will be redirected to the same page on which the user login block was generated (so the same page actually).

To render the user_login_block, you can make use of the drupal_get_form and passing the form name as an argument.

function YOURMODULE_page()
    $build = array();

    // construct your build with parts of the page
    // ...

    if (!user_is_logged_in()) {
        // user not logged in, add the login form
        $build['user_login'] = drupal_get_form('user_login_block');

    return $build;

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.