I want to make customize login form in Drupal 7 theme with custom labels for username and password and also custom submit button but i don't know how to customize it.
Please explain me in detail how can i do it?

Comments

Web Assistant’s picture

This might get you started http://drupal.org/node/19855

yarthesh’s picture

Hi there,

To customize labels for username and password you need to use alter form in your customize module or template.php.

function your_template_form_user_register_form_alter(&$form, &$form_state, $form_id) {
    $form['account']['name']['#title'] = t('Change name');
    $form['account']['pass']['#title'] = t('Change name');
}

or

function your_modulename_form_user_register_form_alter(&$form, &$form_state, $form_id) {
    $form['account']['name']['#title'] = t('Change name');
   $form['account']['pass']['#title'] = t('Change name');
}

For theming
you can do with CSS or use a template file.
you can find more information for theming here https://drupal.org/node/19855

I hope this info will help you

Yarthesh acharya

Rajatarora’s picture

I did this,
it doesn't worked out
I want to unset the create new account and change text for request new password also.
But nothing worked out

Web Assistant’s picture

Can you post your hook_form_alter code for us to see?

Rajatarora’s picture

<?php
function deliver_theme(&$existing, $type, $theme, $path) {
  
    $hooks['user_login'] = array(
    'template' => 'templates/user_login',
    'render element' => 'form',
    // other theme registration code...
  );
  return $hooks;
}
function deliver_form_user_login_block_alter(&$form){
    unset($form['links']);
    unset($form['actions']['request_password']);
    
    
    
    $variables['form']['name']['#value'] = $variables['form']['Email']['#title'];
  $variables['form']['pass']['#value'] = $variables['form']['password']['#title'];
 
}
?>

I am using the above code i can now hide create new account and request new password but i am not able to change the username to Email and change the submit button into image

Web Assistant’s picture

A few things:

I wouldn't hide 'create new account' and 'request new password' using hook_form_alter. Instead I'd do the following:

  • Go to Home » Administration » Configuration » People and under Who can register accounts? select Administrators only.
  • Install the No request new password module

As to customising the form, you are customising only the login block, there is also the general login form, so you need to account for that. Also not sure why you are using $variables, I think you might be misunderstanding the instructions at http://drupal.org/node/19855. Anyway, I'd do something like the below:

<?php
/**
 * Implements hook_form_alter().
 */
function deliver_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == 'user_login' || $form_id == 'user_login_block') {

    // change the labels
    $form['name']['#title'] = t('My name label here');
    $form['pass']['#title'] = t('My password label here');
   
  }
}

?>

Then I would just use CSS to change the look.