Customizing and Overriding User Login page, Register, and Password Reset in Drupal 7 -

Public

SOURCE:
https://www.drupal.org/node/350634

Customizing the user login, register, and password reset pages is fairly simple, and uses the following concepts:

preprocessing to set variables
registration of functions in the theme registry
creation of one or more theme templates.

The 'path' lines tell Drupal where to find the .tpl.php files. This is optional, and in the code above, 'path' tells Drupal to find the files in the templates subdirectory of the theme's base directory.
Note the "_form" added to the user_register element.
Note: As it is the case for D6, it's user_pass not user_password

</> CopyGet raw version
php
  1. <?php
  2. function yourtheme_theme() {
  3. $items = array();
  4.  
  5. $items['user_login'] = array(
  6. 'render element' => 'form',
  7. 'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
  8. 'template' => 'user-login',
  9. 'preprocess functions' => array(
  10. 'yourtheme_preprocess_user_login'
  11. ),
  12. );
  13. $items['user_register_form'] = array(
  14. 'render element' => 'form',
  15. 'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
  16. 'template' => 'user-register-form',
  17. 'preprocess functions' => array(
  18. 'yourtheme_preprocess_user_register_form'
  19. ),
  20. );
  21. $items['user_pass'] = array(
  22. 'render element' => 'form',
  23. 'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
  24. 'template' => 'user-pass',
  25. 'preprocess functions' => array(
  26. 'yourtheme_preprocess_user_pass'
  27. ),
  28. );
  29. return $items;
  30. }
  31. ?>

The preprocess functions simply add a variable into the $vars array that is then displayed in the .tpl.php file. Much more complex manipulation of the content of the render array is possible.

</> CopyGet raw version
php
  1. <?php
  2. function yourtheme_preprocess_user_login(&$vars) {
  3. $vars['intro_text'] = t('This is my awesome login form');
  4. }
  5.  
  6. function yourtheme_preprocess_user_register_form(&$vars) {
  7. $vars['intro_text'] = t('This is my super awesome reg form');
  8. }
  9.  
  10. function yourtheme_preprocess_user_pass(&$vars) {
  11. $vars['intro_text'] = t('This is my super awesome request new password form');
  12. }
  13. ?>

user-register-form.tpl.php

</> CopyGet raw version
php
  1. <p><?php print render($intro_text); ?></p>
  2. <div class="yourtheme-user-login-form-wrapper">
  3. <?php print drupal_render_children($form) ?>
  4. </div>

ALTERNATE::::: template.php

</> CopyGet raw version
php
  1. function yourthemenamehere_theme(&$existing, $type, $theme, $path) {
  2. $hooks['user_login_block'] = array(
  3. 'template' => 'templates/user-login-block',
  4. 'render element' => 'form',
  5. );
  6. return $hooks;
  7. }
  8. function yourthemenamehere_preprocess_user_login_block(&$vars) {
  9. $vars['name'] = render($vars['form']['name']);
  10. $vars['pass'] = render($vars['form']['pass']);
  11. $vars['submit'] = render($vars['form']['actions']['submit']);
  12. $vars['rendered'] = drupal_render_children($vars['form']);
  13. }

ALTERNATE::::::: user-login-block.tpl.php

</> CopyGet raw version
php
  1. <div id="user-login-block-container">
  2. <div id="user-login-block-form-fields">
  3. <?php print $name; // Display username field ?>
  4. <?php print $pass; // Display Password field ?>
  5. <?php print $submit; // Display submit button ?>
  6. <?php print $rendered; // Display hidden elements (required for successful login) ?>
  7. </div>
  8. <div class="links">
  9. <a href="/user/register">Create an Account</a> | <a href="/user/password">Forgot Password</a>
  10. </div>
  11. </div>

YET ANOTHER WAY!!! template.php

</> CopyGet raw version
php
  1. <?php
  2. function THEME_preprocess_user_login_block(&$vars) {
  3. $vars['name'] = render($vars['form']['name']);
  4. $vars['pass'] = render($vars['form']['pass']);
  5. $vars['links'] = render($vars['form']['links']);
  6. $vars['submit'] = render($vars['form']['actions']['submit']);
  7. $vars['rendered'] = drupal_render_children($vars['form']);
  8. }
  9.  
  10. function THEME_form_user_login_block_alter(&$form, &$form_state, $form_id) {
  11. $items = array();
  12. if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
  13. $items[] = l(t('Create Account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
  14. }
  15. $items[] = l(t('Request Password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
  16. $form['links'] = array('#markup' => theme('item_list', array('items' => $items)));
  17. return $form;
  18. }
  19. ?>

YET ANOTHER WAY!!!!! user-login-block.tpl.php

</> CopyGet raw version
php
  1. <div id="user-login-block-container">
  2. <div id="user-login-block-form-fields">
  3. <?php print $name; // Display username field ?>
  4. <?php print $pass; // Display Password field ?>
  5. <?php print $submit; // Display submit button ?>
  6. <?php print $links; // Display submit button ?>
  7. <?php print $rendered; // Display hidden elements (required for successful login) ?>
  8. </div>
  9. </div>