I would like to alter the login form depending how it was accessed. As an example, if the form was access from a particular link, it would display the standard login form. If it was accessed from a different link, then the login form would be modified (ie maybe display a different title and exhibit different behaviour (redirects based on role)).

I figure I need to use hook_form_alter() but I am not sure how to tell which link was clicked. Any ideas how one would go about accomplishing this? I am working with Drupal 6 by the way.


1 Answer 1


Inside your form_alter() hook, you can always check what page a form is on by looking at $_GET['q'], eg:

if ($form_id=='user_login' && $_GET['q']=='different/link') {
  // do form alters here

so if you are at www.yourhost.com/different/link, it will do whatever you tell it to do.

  • I am pretty sure I tried this and it didn't work. I will look at my implementation again and see if I did something wrong.
    – user5013
    Commented Apr 9, 2013 at 18:15
  • let me know, the approach above does work, but the login form is also pretty unique in a lot of ways, especially with redirection, so, it could be something else that is masking the behavior.
    – Jimajamma
    Commented Apr 9, 2013 at 19:35
  • Sorry for not getting back to this sooner but I had a bunch of other stuff on my plate to deal with. I looked at my code more closely and saw that I didn't have it quite set up like you suggested. I changed it to match and it worked. The only thing I had to change was to get the clean url instead the internal url. Otherwise worked great!
    – user5013
    Commented Apr 24, 2013 at 21:46

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.