Hi,

I am trying to add my own login functionlity, and for this i've added mymodule_alter in my module and it is working fine, however, i am facing an issue with user_login_block. I want my site visitors to redirect to registration page if they enter wrong credentials in login form, but unable to do so. Here's what i am trying:

if($login){
drupal_goto('homepage');
}

else{
drupal_goto('registration');
}

control comes in else condition, if i put some message here message gets printed out, but, it never redirects,stays on same page.

What can be the issue here, its working fine incase of user logn form, just doesn't work while coming from user login block.

Thanks,
Kul.

Comments

abhishek sawant’s picture

what are you passing in $login?

Abhishek Sawant
Drupal Developer

kuldeepkaundal’s picture

$login is just a simple check to see if credentials found in database or not.

I've tried all the ways of redirecting to new page, it simply doesn't redirect, even using header('Location') has no effect watsoever, so, i feel there must be some setting that disallows redirects for user login block.

Or is it an undoable task?

kuldeepkaundal’s picture

is there no way to redirect on entering wrong credentials in case of user login block?

kuldeepkaundal’s picture

well, let me reply myself once again, because the solution is:

unset($_REQUEST['destination']);
drupal_goto($url);

mike.roberts’s picture

I currently have a front page that blocks all access to the site and on incorrect login credentials the url points to node?desintation=node. Will your solution fix that? If so, how do I use this? I'm not really a programmer but if I'm pointed to a module file or function that I have to put in my own module I'll be able to figure it out, just need a starting point.

rrmeo’s picture

kuldeepkaundal's suggestion helped in my case too. Here is my code which others might find helpful

function mymodule_user($type, &$edit, &$account, $category = NULL){
  switch ($type){
    // other cases
    case 'login':
      $something_filled = false;
      if (is_array($account->{'profile_custom_list'})) // using a customised selection type profile field
        foreach($account->{'profile_custom_list'} as $field=>$val)
          if (0 !== $val) $something_filled = true;
			
      if (!$something_filled){
        drupal_set_message(t('To complete your registration, please select your favourite color'));
        unset($_REQUEST['destination']); // required if user logs in from block
        drupal_goto(
          url("user/$account->uid/edit/Your%20profile", // where Your profile is a profile category 
            array(
              'absolute'=>true,
              'query' => 'destination=frontpage', // this sets destination AFTER profile update
            )
          )
        );
      }
      break;
  }
}