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, i will move now.

Good

What was the output when you tried your code? It seems you didn't set the prefix/suffix properties correctly. Try:

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

Or, this (assuming name will always preceed pass):

$form['name']['#prefix'] = '<div class="login-fields">';
$form['pass']['#suffix'] = '</div>';

With my code I got only one field was displayed. Thank you so much angheloko. Now it's working fine.

Good

I used

$form['links']['#prefix'] = '<div class="mgnL5 fltL loginLnksCvr test">';
    $form['links']['#suffix'] = '</div>';
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:
<div class="class-name">
         <div class="class-1">Create new account</div>
         <div class="class-2">Request new password</div>
</div>

How can I do this?

Good

You might need to override the 'links' item completely, e.g.:

$items = array();
if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
  $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'), 'class' => array('class-1'))));
}
$items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'), 'class' => array('class-2'))));
$form['links'] = array('#markup' => '<div class="wrapper">'.theme('item_list', array('items' => $items)).'</div>');

When changing another module's form, it helps to check how that module renders the form.

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.

Good