0

In my module tpl file I'm calling

<?php print drupal_render(drupal_get_form('mymodule_login_form')); ?>

Then in my .module file I have this function:

function mymodule_login_form($form, &$form_state){
  $form = drupal_get_form('user_login');
  return $form;
}

So the user_login form gets called and shows up but when I try to use it ( submit it ) I'm always getting the error message: 'The username has not been activated or is blocked.'

When I change the tpl file to: <?php print drupal_render(drupal_get_form('user_login')); ?> it works and giving the correct error messages or logs the user in.

The problem with this is that I'm using it in a popup screen and want to display the error messages in the popup screen using ajax. So I need to alter the user_login form. I know how to do that but I'm not getting past the error message 'The username has not been activated or is blocked.'

2 Answers 2

1

Is there other code going on in mymodule_login_form()? Could you post the full copy/paste of that function? You mentioned that you were altering the form...

Secondly, is there a reason why this alteration couldn't be done using hook_form_alter()? That would be the normal method of altering an existing form.

The error message you are getting will be coming from this function:

user_login_name_validate

Can you think of anything in your code that might be altering the form such that it falls into the if statement contained in that function?

6
  • to keep it simple I removed all the other code altering the form. I'm calling a new form in my template so I think I can't use the form_alter hook to implement a form?
    – FLY
    Sep 24, 2012 at 15:31
  • You should be able to implement hook_form_alter() in your template.php. You shouldn't really do it - that kind of thing ought to be in a module. I just tried it though and it does work. So it would be THEMENAME_form_alter(&$form, &$form_state, $form_id) { ... } Sep 24, 2012 at 15:35
  • well If I can do it in a theme I should be able to do it in my module as well and just call <?php print drupal_render(drupal_get_form('user_login')); ?> in my tpl file and call hook_form_alter() in my module ?
    – FLY
    Sep 24, 2012 at 15:41
  • That should work. Providing that the alterations you are making aren't breaking the form in some way and triggering the error you were getting. Sep 24, 2012 at 15:44
  • 1
    This is a slight aside, but I should also point out that it would be better practice not to put things drupal_get_form calls in the theming layer. You should probably be considering creating a module which exposes a custom block (see hook_block_info() & hook_block_view()) and outputting your custom html and form in there. Try and keep this kind of code out of the theming layer if possible. Alternatively, you could move Drupal's standard user login block into the appropriate region and just rely on the hook_form_alter() stuff and maybe even hook_block_view_alter() to alter the existing block. Sep 24, 2012 at 15:49
1

If your requirement is displaying user login form in AJAX POPUP then you can consider Ajax Login/Register module.

  • This module provides a block with 2 links (Login, Register) for the anonymous user.
  • When the user clicks on Login or register the requested form appears in a nice ajax popup.
1
  • Thanks for the suggestion but I should explain that I'm building a custom form display. I looked at the module but It isn't going to help me out because I need it intergrated with my other form. Also the code of this module isn't helping me because I can't figure out how it is working :(
    – FLY
    Sep 24, 2012 at 15:23

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.