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'] = ' <a class="user-password" href="/user/password">' . t('Forgot username or password?') . '</a>';
$form['name']['#title'] = t('Username'); // Change text on form
$form['name']['#attributes'] = array('placeholder' => t('Username'));
$form['pass']['#title'] = t('Password');
$form['pass']['#attributes'] = array('placeholder' => t('Password'));
$form['actions']['submit']['#value'] = t('');
}
My Custom Validate Module
function hook_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'user_login_block'){
$form['#validate'][] = '_custom_validation';
}
}
function _custom_validation(&$form, &$form_state){
$query = db_select('users', 'u');
$query->fields('u', array('name'));
$query->condition('u.name', $form_state['values']['name'], '=');
$result = $query->execute();
$name = $result->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?