User Login Form Error Message Problem I'm adding the user login form to the homepage of my site and through printing it out in my page.tpl.php, the validation is getting lost a bit.   The first time I enter in an incorrect username or password, nothing happens, but the second time everything acts as it should. I am confused about why it does not display the first time. 

In my page.tpl.php

print drupal_render(drupal_get_form('user_login_block'));


In my template.php

if ($form_id == "user_login_block") {
  $form['links']['#markup'] = ' &lt;a class="user-password" href="/user/password"&gt;' . t('Forgot username or password?') . '&lt;/a&gt;'; 
  $form['name']['#title'] = t('Username'); // Change text on form
  $form['name']['#attributes'] = array('placeholder' =&gt; t('Username'));
  $form['pass']['#title'] = t('Password');
  $form['pass']['#attributes'] = array('placeholder' =&gt; t('Password'));
  $form['actions']['submit']['#value'] = t('');
}


My Custom Validate Module

function hook_form_alter(&amp;$form, &amp;$form_state, $form_id){
  if($form_id == 'user_login_block'){
    $form['#validate'][] = '_custom_validation';
  }
}

function _custom_validation(&amp;$form, &amp;$form_state){
  $query = db_select('users', 'u');
  $query-&gt;fields('u', array('name'));
  $query-&gt;condition('u.name', $form_state['values']['name'], '=');
  $result = $query-&gt;execute();
  $name = $result-&gt;fetchField();
  if(empty($name)){
    form_set_error('user_name', t('Username or password could not could not be found.'));
  }
}


I also have the module "Email Registration" Installed, not sure if this has anything to do with it also.

Would anyone know anything about this?
What is the reason for you adding the form in that manner and having custom validation etc. when drupal already gives you this?

For example, why not just use the drupal block system or the context module to place the login block on your homepage within one of the regions?

Another thing is that your custom module should not have  

function hook_form_alter(&amp;$form, &amp;$form_state, $form_id)


it should be  

function MODULE_NAME_form_alter(&amp;$form, &amp;$form_state, $form_id)


Where you replace MODULE_NAME with your module's name.
Although maybe you only had it that way for this post.

Also, regardless of the method you use to show the user_login_block form, it already has its own validation functions that come with it. It already has these three validation functions:
http://api.drupal.org/api/drupal/modules!user!user.module/function/user_login_name_validate/7
http://api.drupal.org/api/drupal/modules!user!user.module/function/user_login_authenticate_validate/7
http://api.drupal.org/api/drupal/modules!user!user.module/function/user_login_final_validate/7  

With the last of those doing (among other things) essentially the same validation your custom function is trying to do.

You can still use the form alter to add your attributes and change titles, etc. 
In this case though the module weight does not matter.
It only matters if two modules are both using hook_form_alter() and are changing the same parts of the form.