I have a small problem on D7, I need to alter the login form inside block (add class to inputs, placeholder and submit button text, custom pass reset and login links) im using hook_form_FORM_ID_alter. I don't need to use custom module.
block id = block-user-login, form id = user_login_block
My theme.php code
function themename_form_user_login_block_alter(&$form, &$form_state) {
$form['name']['#attributes']['placeholder'] = t( 'Username' );
$form['pass']['#attributes']['placeholder'] = t( 'Password' );
// custom register link
$form['actions']['signup'] = array(
'#markup' => l(t('Register'), 'user/register', array(
'attributes' => array(
'class' => 'top-user-block-link register',
'title' => t('Create a new user account.')
)
)),
);
// custom reset password link
$form['actions']['request_password'] = array(
'#markup' => l(t('Forgot my password'), 'user/password', array(
'attributes' => array(
'class' => 'top-user-block-link new-password',
'title' => t('Request new password.'),
)
)),
);
}
Links for password reset and login links renders fine, but i can't make the placeholders or class add to work.
i've tried to use
function theme_form_alter(&$form, &$form_state, $form_id){
if ($form_id === 'user_login_block') {
$form['name']['#attributes']['placeholder'] = t( 'Username' );
$form['pass']['#attributes']['placeholder'] = t( 'Password' );
}
}
but i works only on /login page.