I've implemented a menu using hook_menu(),the page callback function checks if user is login or not, if user is logged in a form for creating a content of type 'request' is loaded if not using drupal_get_form, user login block is loaded.

Now what I'm looking for is when user signed-in, he/she returned back to this page so now he can fill the form.

I don't want all user login event redirected to this page, so now my question is :

How to redirect a form just if the form is loaded in specific page(url)?

1 Answer 1


It can be accomplished adding 3 functions to your custom module:

The first one is to implement hook_form_alter():

function my_module_form_alter(&$form, &$form_state, $form_id){
  if($form_id=='user_login') { // It will be executed only on this form.
    // Check if the form is loaded in your custom path.
    if (current_path() == 'my_custom_path') {
      array_push($form['#submit'], 'my_module_login_custom_path_submit');
    else {
      array_push($form['#submit'], 'my_module_login_user_submit');

The second one is to implement the redirect to your custom path:

function my_module_login_custom_path_submit(&$form, &$form_state){
  $form_state['redirect'] = 'my_custom_path';

The third one is to implement the redirect to user page:

function my_module_login_user_submit(&$form, &$form_state){
  $form_state['redirect'] = 'user';

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.