I was having a problem with using the Login block form on the home page. Error messages related to the login (e.g. "Password incorrect.", etc.) were not getting dispalyed when the login failed. They would show up only after reloading the page again.
In my template, I had this:
<div class="content">
<?php print drupal_get_form('user_login_block'); ?>
</div>
What I figured out was that the error messages weren't actually being generated until after the call to drupal_get_form() was made. Because this call was inside the template, they were not set for the template to display.
The fix for this is to create a function to make the call to drupal_get_form() and grab the resulting error messages (if any). So, in a module or in template.php, you need to create a function like this:
function THEMENAME_get_login_block() {
$form = drupal_get_form('user_login_block');
return theme_status_messages().$form;
}
Then, in your template, do this instead:
<div class="content">
<?php print THEMENAME_get_login_block() ;?>
</div>
This makes sure that the error messages are set before the form and the mesages themselves are displayed.
This blog post was originally published on embiggen.net.
1 Comment
thankyou