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 dhineshkumar on
I have assigned class names to both user name & password text fields in user login block separately like this and it's working.
function mymodule_form_alter(&$form, &$form_state, $form_id, $element) {
if ( TRUE === in_array( $form_id, array( 'user_login', 'user_login_block') ) ) {
$form['name']['#attributes']['class'] = array('mgnB10', 'fntXL', 'drkFg1');
$form['pass']['#attributes']['class'] = array('fntXL', 'drkFg1');
}
}
I want to include these fields inside a single '
' and assign class name for design purpose. For example:
<div class="login-fields">
<user-name text field>
<password text-field>
</div>
I gave the following code but I didn't get expected output:
function mymodule_form_alter(&$form, &$form_state, $form_id, $element) {
if ( TRUE === in_array( $form_id, array( 'user_login', 'user_login_block') ) ) {
$form['user_login']['#attributes']['class'] = array('#prefix' => 'myclass');
$form['name']['#attributes']['class'] = array('mgnB10', 'fntXL', 'drkFg1');
$form['pass']['#attributes']['class'] = array('fntXL', 'drkFg1');
$form['user_login'] = array('#suffix' => '</div>');
}
}
Comments
=-=
this question is better served in the 'module development and code questions' forum. Please edit the opening post and move it.Thanks.Thanks VM
Thanks VM, i will move now.
What was the output when you
What was the output when you tried your code? It seems you didn't set the prefix/suffix properties correctly. Try:
Or, this (assuming name will always preceed pass):
Thank you so much
With my code I got only one field was displayed. Thank you so much angheloko. Now it's working fine.
I used $form['links']['
I used
for #links (Create new account, Request new password) just below to text fields. I want to set class name to each links and same class name for both links. For example:
How can I do this?
The problem is that 'links' already contains the rendered markup
You might need to override the 'links' item completely, e.g.:
When changing another module's form, it helps to check how that module renders the form.
Thanks it's work, but
Thanks, angheloko. It's working(alone). I gave that code in my theme's template.php file. I'm using ajax_register module. When I give the above code I didn't get light box effect, instead that it redirects to drupal's default account creation page. But custom class names are rendered. What I have to do in order to get light box effect of ajax register module.? Please guide me. Thanks.