A fix for Drupal form error messages not showing up
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.
13 comments
Thanks!
Thanks for posting - was having real issues with this!
great tip
Really good tip, was having this same issue as well and never thought it might be a theme related problem
Thank you
Here's a message from another person you helped out a lot!
Thanks for the tutorial...it
Thanks for the tutorial...it works for me!
Good fix
This is a good one.
Thanks
Thanks Its really Good
Thanks
Its really Good
Thanks its' work well
Thanks its' work well
messages status is not
messages status is not showing when logout in drupal
Please help me,am not able to
Please help me,am not able to see message status when am log out....
thanks...
Thanks for posting. :-)
Thanks for posting. :-)
Who would've guessed? Post
Who would've guessed? Post from 2009 will solve my problem. Thanks a bunch :)
Thanks so much man, this is
Thanks so much man, this is so very unclear in drupal!
This function - theme_status
This function - theme_status_messages() did the trick.
Thanks.