[development] redirect login block when user enters wrong user/pass

Saint-Genest Gwenael gwenael.saint-genest at makina-corpus.com
Wed Oct 31 18:44:59 UTC 2007


    Your "drupal_goto()" doesn't work because at this point the value
of $_REQUEST['destination'] is already set [1]. So your drupal_goto()
will reload the page but not with 'user'. After reload no validation
is needed, your function is not called :(

I think, a quick solution is to unset 'destination' value before
calling drupal_goto() :

 function myutility_user_login_validate($form_id, $form_values) {
   user_login_validate($form_id, $form_values);
   if (count(form_get_errors()) > 0) {
     drupal_set_message('test error message');

It's not a beauty solution but i think it's the simplest :)


[1] http://api.drupal.org/api/function/drupal_goto/5

John Barreiros wrote:
> Hi
> First, I realize what I'm doing isn't the most usable, but it's how the
> client wants it.
> On the homepage, the user login block is styled all fancy and compact.
> Unfortunately, it's compactness prevents a place for an error message if the
> user messes up their username or password.
> So, what I'd like to do, when the form fails validation, is redirect the
> user to "/user" which displays the regular login form along with the error
> messages that would of displayed within the block.
> I tried the following (in my own module),
> function myutility_form_alter($form_id, &$form) {
>   switch ($form_id) {
>     case 'user_login_block':
>       $form['#validate'] = array('utility_user_login_validate' =>
> array($form_id, $form));
>       unset($form['links']);
>       break;
>   }
> }
> function myutility_user_login_validate($form_id, $form_values) {
>   user_login_validate($form_id, $form_values);
>   if (count(form_get_errors()) > 0) {
>     drupal_set_message('test error message');
>     //print "here";
>     drupal_goto('user');
>   }
> }
> The drupal_goto doesn't seem to work here. I'm fairly confident the code is
> making it to the drupal_goto because if I uncomment the "print" statement is
> does get called and prints out "here".
> Any ideas why drupal_goto isn't working in this case?
> Thanks for the help.

More information about the development mailing list