1

I am using drupal 7 and would like to customise my login form block.

function theme_form_alter(&$form, &$form_state, $form_id) {  

if ($form_id == "user_login_block") { $form['links'] = Null; // Remove Request New Password and other links from Block form //$form['links']['#markup'] = t('Forgotten Password?') . ' ' . t('Forgotten Password?') . ''; // Remove Request New Password from Block form //$form['links']['#markup'] = ' ' . t('Register') . '' . ' ' . t('Forgotten Password?') . ''; // Remove Request New Password from Block form

    $form['#prefix'] = '<div class="nano-ui">';
    $form['#suffix'] = '</div>';

    $form['name']['#attributes']['class'][]= array("nui-input");




    $form['name']['#title'] = Null; // Change text on form
    $form['name']['#attributes'] = array('placeholder' => t('username'));
    $form['pass']['#title'] = Null;
    $form['pass']['#attributes'] = array('placeholder' => t('password'));


}

}

In the above code the following line does not seem to have any effect on my field :

$form['name']['#attributes']['class'][]= array("nui-input");

1 Answer 1

2

This is what will work

    $form['#prefix'] = '<div class="nano-ui">';
    $form['#suffix'] = '</div>';

   $form['name']['#title'] = Null; // Change text on form
    $form['name']['#attributes'] = array('placeholder' => t('username'));
    $form['pass']['#title'] = Null;
    $form['pass']['#attributes'] = array('placeholder' => t('password'));

    $form['name']['#attributes']['class'][] = 'nui-input';

Here is the reference : How do I use hook_form_alter() to add CSS classes to a custom input field in user_register_form?

3
  • Please mark it as answered if it helped.
    – Bhuvana
    Commented Mar 4, 2016 at 4:43
  • Hi tried cleared the cache and unfortunately it did not work
    – yazzou
    Commented Mar 6, 2016 at 15:34
  • Updated my answer. The order of statements matter. $form['name']['#attributes'] = array('placeholder' => t('username')); is replacing the complete attributes array and the changes made to the array before that will have no effect. Add the class after the setting the attributes array.
    – Bhuvana
    Commented Mar 7, 2016 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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