Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Mojtaba Reyhani on
I'm trying to customize user login form in (/user/login) page and I want to use a hook_form_alter function to add some awesome style and placeholder to each of user login form fields and remove or hide:
"Enter your admin username" and "Enter the password that accompanies your username" description expressions under each of theme.
I added something like below code to my ThemeName.theme:
function ThemeName_form_alter(&$form, $form_state, $form_id) {
if ( $form['#form_id'] == 'user_login_form' ) {
$form['actions']['submit']['#attributes']['class'][] = 'button glow button-primary expanded';
$form['keys']['#attributes']['placeholder']['name'] = t('User Name');
$form['keys']['#attributes']['placeholder']['password'] = t('Password');
}
}
and I want to Achieve something like below image:
User Login Form
Comments
ok.
ok.
What's this means?
Is this means that I cant add a forum topic?
I don't understand the
I don't understand the question - you already started this forum topic.
He is reading is your
He is reading is your signature - which is very confusing.
I answered his question on Drupal Answers.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
He is reading is your
Ahh, I pointed out that the signatures don't have enough visual delineation from the posts months ago. Completely ignored. And I've seen the same mistake made between other users in the past too.
But as always, the people in charge don't care, because it's just the forums, and the forums don't matter to them.
He was not confused because
He was not confused because of the design, but rather the content, which you have full control over.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
If the design clearly
If the design clearly delineated the signature from the post, the confusion would not exist. It's only because someone who doesn't know the forum cannot clearly see the delineation, that the confusion exists.
=-=
form_alters should go into custom modules. If you want to attempt at the theme layer see https://www.drupal.org/node/1949472
Sorry VM but that is not
Sorry VM but that is not correct and there is no "attempting" form alters in the theme layer when themes have access to form alters - zero difference to a module.
This is a design related change, not business logic - it very much should be in the theme.
Design decisions == theme level customisations. Drupal core supports
hook_form_alter()
in the themes for that very reason - because there are many design related changes one may wish to make to a form - alterations that belong firmly in the theme/view layer.Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
I agree with Jeff. Form logic
I agree with Jeff. Form logic goes in modules. Form output alterations belong in themes - unless the change should persist even with a change in themes, in which case it's better to put it into a module. My login form customizations are split between both. I change the help text in modules, and change ordering and adding/removing other elements in the theme.