I am creating my own theme for my website, and am having an issue with the user_login_block form. I have a simple jQuery dropdown style content div in which I am outputting the form, and have no clue why it is not displaying status messages (invalid login attempts, ect..). When entering incorrect credentials, the page simply refreshes and nothing is displayed to the end user. I am new to Drupal, but not new to PHP. I have no idea what I could be doing wrong. My code is below, any help would be much appreciated.


function dtn_form_alter(&$form, &$form_state, $form_id) {
    switch($form_id) {
        case 'user_login_block':            
            $form['links']['#markup'] = '<ul class="dtn-user-login-menu-links"><li><a href="/user/password">' . t('Request new password') . '</a></li></ul>';
            $form['name']['#title'] = Null;
            $form['name']['#attributes'] = array('placeholder' => t('Username'));
            $form['pass']['#title'] = Null;
            $form['pass']['#attributes'] = array('placeholder' => t('Password'));

Login Form Source:

$userLoginForm = drupal_get_form('user_login_block');

$output .= '<ul class="dtn-user-bar-content-list">';
$output .= '<li class="dtn-user-menu-login-link"><a class="dtn-user-menu-trigger-login" href="#">' . t('Login') . '</a>';
$output .= '<div class="dtn-user-menu-content">';
$output .= render($userLoginForm);
$output .= '</div>';
$output .= '</li>';
$output .= '<li class="dtn-user-menu-register">' . t('<a href="!url">Register</a>', ['!url' => url('user/register')]) . '</li>';
$output .= '</ul>';

$output = '<div class="dtn-user-bar-content">' . $output . '</div>';

return $output;


  • Do you see any other messages from other forms? If not, make sure you have a <?php print $messages; ?> somewhere in your theme's page.tpl.php file. – Jimajamma Aug 11 '13 at 22:58
  • You are an absolute life saver! I am still very new to Drupal, and wasn't aware of that variable. I searched the web high and low for the last 2 days before I asked my question, guess I was searching for the wrong information. Thank you again!! – RPelham Aug 12 '13 at 4:41

I think you are embedding Login Form directly in .tpl file. Either assign login block to some region or bring it through a variable from hook_preproces_page() function.


In Drupal 7, the messages the modules print with drupal_set_message() aren't rendered from any block but, as Jimajamma says, they are rendered from Drupal when rendering the page. The page template, which in Drupal 7 is the page.tpl.php file receives the HTML markup for the messages in the $message variable. The template file render those messages with code similar to the following.

<?php if ($breadcrumb): ?>
  <div id="breadcrumb"><?php print $breadcrumb; ?></div>
<?php endif; ?>

<?php print $messages; ?>

<div id="main-wrapper"><div id="main" class="clearfix">

The code before and after the line printing the messages can vary from theme. For example, the Bartik theme uses the following code.

  </div></div> <!-- /.section, /#header -->

  <?php if ($messages): ?>
    <div id="messages"><div class="section clearfix">
      <?php print $messages; ?>
    </div></div> <!-- /.section, /#messages -->
  <?php endif; ?>

  <?php if ($page['featured']): ?>
    <div id="featured"><div class="section clearfix">
      <?php print render($page['featured']); ?>
    </div></div> <!-- /.section, /#featured -->
  <?php endif; ?>

Without the <?php print $messages; ?> line, the messages will not be visible in the page. If you are using a custom theme, be sure to include it inside your page.tpl.php template.


Exactly. If you embed direct the user_login_block into any tpl files, it won't render any error messages for the first time as the error message will render after the tpl files was render.

It need to be declare in hook_preprocess_page() to make sure the error message is pass before any tpl files rendered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.