Last updated October 10, 2014. Created on December 23, 2008.
Edited by SERVANT14, bisonbleu, drupalshrek, dee2006. Log in to edit this page.

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.

Step 1.
In the site theme directory, create or edit your template.php file.

Step 2.
The first step is to implement hook_theme for your theme. In the template.php file for your theme, look for a function named yourtheme_theme() and modify it to add these return values. If the function doesn't exist, add the following:

For D6:

<?php
/**
 * Registers overrides for various functions.
 *
 * In this case, overrides three user functions
 */
function yourtheme_theme() {
  return array(
   
'user_login' => array(
     
'template' => 'user-login',
     
'arguments' => array('form' => NULL),
    ),
   
'user_register' => array(
     
'template' => 'user-register',
     
'arguments' => array('form' => NULL),
    ),
   
'user_pass' => array(
     
'template' => 'user-pass',
     
'arguments' => array('form' => NULL),
    ),
  );
}
?>

Notes about that code:

  • Change the function name by replacing "yourtheme" with the name of your theme
  • The template can be the same for all three. The example above uses a different template for each case: user-login, user-register, and user-pass
  • The template names must use a dash, not an underscore
  • Note: It's user_pass not user_password

For D7:

<?php
function yourtheme_theme() {
 
$items = array();
   
 
$items['user_login'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
   
'template' => 'user-login',
   
'preprocess functions' => array(
      
'yourtheme_preprocess_user_login'
   
),
  );
 
$items['user_register_form'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
   
'template' => 'user-register-form',
   
'preprocess functions' => array(
     
'yourtheme_preprocess_user_register_form'
   
),
  );
 
$items['user_pass'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
   
'template' => 'user-pass',
   
'preprocess functions' => array(
     
'yourtheme_preprocess_user_pass'
   
),
  );
  return
$items;
}
?>

Notes about the D7 version:

  • 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

Step 3.
Now you implement three preprocess functions. There may be more concise ways to code this, but this works very well and is easy to read, so here we go!

For D6:

<?php
function yourtheme_preprocess_user_login(&$variables) {
 
$variables['intro_text'] = t('This is my awesome login form');
 
$variables['rendered'] = drupal_render($variables['form']);
}

function
yourtheme_preprocess_user_register(&$variables) {
 
$variables['intro_text'] = t('This is my super awesome reg form');
 
$variables['rendered'] = drupal_render($variables['form']);
}

function
yourtheme_preprocess_user_pass(&$variables) {
 
$variables['intro_text'] = t('This is my super awesome insane password form');
 
$variables['rendered'] = drupal_render($variables['form']);
}
?>

Notes about that code:

  • Change the function name by replacing "yourtheme" with the name of your theme
  • The line $variables['intro_text'] adds the text that follows to the $variables array, which gets passed to the template as $intro_text
  • The second line renders the form and adds that code to the $variables array, which gets passed to the template as $rendered

For D7:
The code is even simpler for D7 because we don't need to pass a variable containing the form content we want rendered. The variable exists already in the $vars array and can be rendered in the .tpl.php file.

<?php
function yourtheme_preprocess_user_login(&$vars) {
 
$vars['intro_text'] = t('This is my awesome login form');
}

function
yourtheme_preprocess_user_register_form(&$vars) {
 
$vars['intro_text'] = t('This is my super awesome reg form');
}

function
yourtheme_preprocess_user_pass(&$vars) {
 
$vars['intro_text'] = t('This is my super awesome request new password form');
}
?>

The above 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.

Please note, that the preprocess functions should go into the template.php file.

Step 4.
Create template files to match the 'template' values defined above.

For D6
We need the following template files (make sure to use a dash, not an underscore) :

  • user-login.tpl.php
  • user-register.tpl.php
  • user-pass.tpl.php

For D7
Same as D6, except using user-register-form.tpl.php instead of user-register.tpl.phpfor the register form.

Step 5.
Paste the following into user-login.tpl.php. Modify as necessary for user-register.tpl.php (D6) and user-register-form.tpl.php (D7):

For D6:

<p><?php print $intro_text; ?></p>

<div class="my-form-wrapper">
  <?php print $rendered; ?>
</div>

For D7:

<p><?php print render($intro_text); ?></p>
<div class="yourtheme-user-login-form-wrapper">
  <?php print drupal_render_children($form) ?>
</div>

Note the change to the syntax for causing Drupal to render the form. Also, the D7 sample uses a different class for the div, but that's just a matter of preference.

Step 6.
Save your template.php file to the theme's main directory. Save your .tpl.php files in the same place for the D6 examples, or, in the case of the D7 examples, to the directory you specify in the 'path' element of the $items array.

Step 7.
Rebuild the cache. Go to Administration > Performance and click on "Rebuild Cache" on the bottom of the page.

Now, the user login page will contain the new text from the preprocess function, and the tpl.php file(s) can be modified to suit the site's needs.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

jwero’s picture

Step 2 wouldn't work for me because my template.php already had that method declared using hooks. I added to my existing mytheme_theme method the following code:

Snippet:

$hooks['user_login'] = array(
'template' => 'user-login',
'arguments' => array('form' => NULL)
);

My full method ended up like so:

/**
* Implementation of HOOK_theme().
*/
function jztheme_theme(&$existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);

$hooks['user_login'] = array(
        'template' => 'user-login',
        'arguments' => array('form' => NULL)
  );
  return $hooks;
}

This worked for me, when I followed the other steps listed. I hope it helps someone else as well.

jsimonis’s picture

Thanks! This is exactly what I needed. I kept overlooking that there was already a hook in the template file.

--
Jenni S.
http://www.nulookmedia.net
Portland, OR metro area
Contact Me

aaron.dietrich’s picture

I'm using a Zen subtheme and had to incorporate the user-register code into the hooks. Working great now! Since my theme has a sub-directory called "templates," where all the tpl's are located, I had to adjust the template path. So, my theme method looks like this:

function freeflow_theme(&$existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);

$hooks['user_register'] = array(
   'template' => 'templates/user-register',
      'arguments' => array('form' => NULL)
  );
return $hooks;
}

jrz’s picture

Hi all!
I'm using the following function to change the user registration form which only displays first name, last name and email. It works well, however when i want to add a user from the admin section i get the same form which is not what i want. I need to have the core registration form for administrators so they can set the password and allocate a role. How can I change this function so it only works for anonymous users?
function mytheme_theme($existing, $type, $theme, $path) {
return array(
'user_register' => array(
'arguments' => array('form' => NULL),
'template' => 'templates/user-register', // this is the name of the template
),
);
}

tebb’s picture

After a little searching and reading, I found that you can use http://drupal.org/project/potx to extract translation strings that use the t() function from themes (as well as modules).

I guess this works for template files .tpl.php, phptemplate.php and javascript files, but I haven't tried it yet.

Potx creates a pot file. A translator takes this and creates something like spanish.po, russian.po. You then place the .po files in a translations subdirectory of your theme (or module).

There is additional useful reading about multilingual javascript in 'Adding A Translated String' section of: http://www.packtpub.com/article/translations-in-drupal-6

jdtart’s picture

I am upgrading a Drupal 5.x site, and I have everything working great except for the custom login page. On the older Drupal 5.x site, I used a callback function (now depreciated in D6) so that when I visit my site at http://www.mysite.com/, the custom login page appears (it also is present if I go to http://www.mysite.com/user). But with Drupal 6, I cannot seem to get that same functionality. I must go to http://www.mysite.com/user to get the custom page. That is not acceptable; I need the login page to appear for all non-authenticated users accessing the root of the site.

What am I missing??

sbsoft’s picture

The solution is to override user_login_block ( not user_login ):

function YOUTHEME_theme(&$existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);

$hooks['user_login_block'] = array(
'template' => 'user-login',
'arguments' => array('form' => NULL)
);

// @TODO: Needs detailed comments. Patches welcome!
return $hooks;
}

function YOUTHEME_preprocess_user_login_block(&$variables) {
$variables['intro_text'] = t('This is my awesome login formX');
$variables['rendered'] = drupal_render($variables['form']);
}

Please somebody let me know if it is the right solution!

Thanks
Stefano

kravtsov’s picture

mxh’s picture

Drupal 7 issue:
I get my custom template, I get all vars (finally) into this template, but i get following error message after first login:

"Notice: Undefined index: render element in theme() (line 811 from/drupal/includes/theme.inc).."

Someone knows how to do it correctly in Drupal 7? I'm trying for days now... thanks

---

For those who are interested, here's my code to implement my custom template:

<?php
function mytheme_theme() {
return array(
'user_login_block' => array('template' => 'user-login-block''arguments' => array('form' => NULL)
));
}

function

mytheme_preprocess_user_login_block(&$variables) {
 
##var_export($variables);
$variables['form'] = $variables['']; // With this, I can print in the template $form['name'] and so on
 
}
?>

-- EDIT: SOLVED for Drupal7

note: I'm a beginner in Drupal at all, so the following is called a dirty "work-around". Someone who knows a nice solution, please feel free to publish.

code snippet:

<?php
function mytheme_theme() {
  return array(
   
'user_login_block' => array(
     
'template' => 'user_login_block', ## storage template in mytheme/user_login_block.tpl.php
     
'variables' => array('form' => NULL), ## you may remove this line in this case
   
),
  );
}

function

mytheme_preprocess_user_login_block(&$variables) {
 
$variables['form'] = drupal_build_form('user_login_block', user_login_block(array())); ## I have to build the user login block on myself.
 
}
?>

and here is an example content of the stored user_login_block.tpl.php :

<div>custom user login block</div>
<?php
                       
## just a test to see if $form is transfered
            ##var_export($form);
                
                 
print drupal_render($form['name']);
                  print
drupal_render($form['pass']);
                  print
drupal_render($form['links']);
                          print
drupal_render($form['form_build_id']);
                      print
drupal_render($form['form_id']);
                      print
drupal_render($form['actions']);
                 
           
?>

With this, I get no error message. It's not a good one, I know.
Hope I helped someone with this. Sorry for my bad english.

hubris’s picture

I believe the description for what this code snippet does is misleading...

"Customizing the user login, register, and password reset pages is fairly simple"

This code doesn't customize the PAGE, it customizes the content area of the page, mainly the form for user-login , register, etc.

mugginsoft.net’s picture

Once you start using template files in earnest your theme folder soon becomes unruly.
Some form of folder hierarchy soon becomes a necessity.

Drupal will search subfolders in your theme when searching for template suggestions.
When using hook_theme you can direct the template to a forms folder within your theme.

At present my theme contains the following folder hierarchy within my_theme/templates:

blocks - block.tpl.php and block overrides
boxes - box.tpl.php
comments - comment.tpl.php
forms - login, register and password form templates
nodes - node.tpl.php and custom CCK node templates
pages - page.tpl.php and custom page templates
views - views search templates, table templates and exposed form templates

The root of my_theme now need only contain: my_theme.info, style.css and template.php.
Refresh the theme registry after reorganising your templates.

<?php
/**
* Registers overrides for various functions.
*
* In this case, overrides three user functions
*/
function yourtheme_theme() {
  return array(
   
'user_login' => array(
     
'template' => 'templates/forms/user-login',
     
'arguments' => array('form' => NULL),
    ),
   
'user_register' => array(
     
'template' => 'templates/forms/user-register',
     
'arguments' => array('form' => NULL),
    ),
   
'user_pass' => array(
     
'template' => 'templates/forms/user-pass',
     
'arguments' => array('form' => NULL),
    ),
  );
}
?>
espirates’s picture

So what would you enter in the user-login, user-register and user-pass tpl pages ?

skyself’s picture

Very useful comment thanks !! It seems a couple of Zen themes' users have problems not locating their templates in the right place.
Bye

steveadamo’s picture

For those that arent aware, you can extend this lesson to create a custom page for each of the various forms.

So, user-register.tpl.php would have a corresponding page.tpl.php file of page-user-register.tpl.php. This allows you to have complete control over the user registration page/form.

-----------------------------
Find. Meet. Play!
http://www.weplaygroup.com

momper’s picture

is there a possibility to combine login/password/register on one page?

Bthabault’s picture

I realize this thread is rather old but I am extremely new to drupal and am curious about this post.

Thanks

UPDATE Problem solved easy fix!

Siripong’s picture

For /user/login in D7, page--user--login.tpl.php

fletch11’s picture

In response to the question about getting the login and registration forms on one page I did it by creating two blocks. In the login block all you have to do is insert this:

<?php print drupal_get_form('user_login')?>

for the registration fom insert this into a bock:

<?php  print drupal_get_form('user_register');  ?>

If you wanted to set them side by side insert both blocks into the content region and theme with css - set width to something like 45% for both and float accordingly

You can see an example here

redpuma’s picture

<?php print drupal_get_form('user_login')?>

Watchout for the missing semi-colon above it caught me out.

<?php print drupal_get_form('user_login'); ?>
sonar_un’s picture

This is the code for Drupal 7

        <?php print drupal_render(drupal_get_form('user_login')); ?>

        <?php print drupal_render(drupal_get_form('user_register_form')); ?>

dalegrebey’s picture

My User Login Block containing this Drupal 7 PHP code:

<?php print drupal_render(drupal_get_form('user_login')); ?>

Causes my website to break with the following Error in Firefox:

The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

borishuai’s picture

When we use hook_theme to register a theme hook, but where does Drupal invoke it by theme function? Or when does Drupal invoke our tpl files when render login/register pages?

Vaene’s picture

I need to change $form['message'], $form['submit'] in the user_pass_reset function. However the function takes the variables &$form_state, $uid, $timestamp, $hashed_pass, $action = NULL and uses them in a bunch of conditionals before finally assigning values to the aforementioned properties at the end. What is the best way to go about overidding $form['message'], $form['submit'] when the original function looks like this:

<?php
function user_pass_reset(&$form_state, $uid, $timestamp, $hashed_pass, $action = NULL) {
  global
$user;

 
// Check if the user is already logged in. The back button is often the culprit here.
 
if ($user->uid) {
   
drupal_set_message(t('You have already used this one-time login link. It is not necessary to use this link to login anymore. You are already logged in.'));
   
drupal_goto();
  }
  else {
   
// Time out, in seconds, until login URL expires. 24 hours = 86400 seconds.
   
$timeout = 86400;
   
$current = time();
   
// Some redundant checks for extra security ?
   
if ($timestamp < $current && $account = user_load(array('uid' => $uid, 'status' => 1)) ) {
     
// Deny one-time login to blocked accounts.
     
if (drupal_is_denied('user', $account->name) || drupal_is_denied('mail', $account->mail)) {
       
drupal_set_message(t('You have tried to use a one-time login for an account which has been blocked.'), 'error');
       
drupal_goto();
      }

     
// No time out for first time login.
     
if ($account->login && $current - $timestamp > $timeout) {
       
drupal_set_message(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'));
       
drupal_goto('user/password');
      }
      else if (
$account->uid && $timestamp > $account->login && $timestamp < $current && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login)) {
       
// First stage is a confirmation form, then login
       
if ($action == 'login') {
         
watchdog('user', 'User %name used one-time login link at time %timestamp.', array('%name' => $account->name, '%timestamp' => $timestamp));
         
// Set the new user.
         
$user = $account;
         
// user_authenticate_finalize() also updates the login timestamp of the
          // user, which invalidates further use of the one-time login link.
         
user_authenticate_finalize($form_state['values']);
         
drupal_set_message(t('You have just used your one-time login link. It is no longer necessary to use this link to login. Please change your password.'));
         
drupal_goto('user/'. $user->uid .'/edit');
        }
        else {
         
$form['message'] = array('#value' => t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to login to the site and change your password.</p>', array('%user_name' => $account->name, '%expiration_date' => format_date($timestamp + $timeout))));
         
$form['help'] = array('#value' => '<p>'. t('This login can be used only once.') .'</p>');
         
$form['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
         
$form['#action'] = url("user/reset/$uid/$timestamp/$hashed_pass/login");
          return
$form;
        }
      }
      else {
       
drupal_set_message(t('You have tried to use a one-time login link which has either been used or is no longer valid. Please request a new one using the form below.'));
       
drupal_goto('user/password');
      }
    }
    else {
     
// Deny access, no more clues.
      // Everything will be in the watchdog's URL for the administrator to check.
     
drupal_access_denied();
    }
  }
}
?>

I have looked everywhere I can think of and have not found anything to help with overriding a function with multiple variables and properties dependent on several conditional statements. Every method I try to change these properties breaks the site. I feel like if I could get a working example on this. I would know 98% of everything I need to know about Drupal. Thanks in advance!

picxelplay’s picture

There is a way easier way to do this. I created a tut because I didn't find any good ones.
http://picxelplay.com/blog/theming-drupal-6-registration-login-and-reque...

----
Sudo Kill Cylons

dadderley’s picture

The tutorial was just what I needed.

picxelplay’s picture

anytime:)

----
Sudo Kill Cylons

.kuma’s picture

Thank you for this, very helpful!

What about the page where you are brought to after clicking on the link in your email?

E.g., http://site.com/user/reset/$userid/$random-hash?

I can't find out how to create a template for this page. Also, I can't find out how to preprocess this in the theme's template.php. I tried this:

function my_theme_preprocess_user_pass_reset(&$vars) {
$vars['form']['submit']['#value'] = "Lorem Ipsum";
$vars['rendered'] = drupal_render($vars['form']);
}

But doesn't work.

tomlobato’s picture

Great article!

I need to do something different: redirect login/pass/register page to custom panel pages. Say /my_custom/login instead /user/login, so /my_custom/login will be my "official" login pages.
Can I put something in templates.php (or another file) so drupal evertime send the user to /my_custom/login instead /user/login?

inf’s picture

Hi,

I'd like to override my user login theme. I use Drupal 7 and Zen sub-theme. I did the steps as described above. Now my code in template.php looks like this:

function yourtheme_theme(&$existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);

$hooks['user_login'] = array(
        'template' => 'user-login',
        'arguments' => array('form' => NULL)
);

return $hooks;
}

function yourtheme_preprocess_user_login(&$variables) {
$variables['intro_text'] = t('This is my awesome login form');
$variables['rendered'] = drupal_render($variables['form']);
}

My problem is the method yourtheme_preprocess_user_login() never called and I get the default login theme on the site.
Any idea?

inf’s picture

Problem solved! I used login block and thats why that function never called. Here is the solution:

function yourtheme_theme(&$existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);

$hooks['user_login_block'] = array(
'template' => 'user-login',
'arguments' => array('form' => NULL)
);

return $hooks;
}

function yourtheme_preprocess_user_login_block(&$variables) {
$variables['intro_text'] = t('This is my awesome login form');
$variables['rendered'] = drupal_render($variables['form']);
}

tazir1’s picture

In D7 no longer need to call zen_theme()
http://drupal.org/node/1066436

zanlus’s picture

Look, this works fine for adding in a few custom content chunks, but it doesn't allow manipulation of the user-registration form itself, which should be included in this how-to. Can someone point me to anything that indicates how the form itself can be manipulated?

Thanks.

zanlus

webservant316’s picture

First I created myzensubtheme/user-profile.tpl.php thus...

<?php
   
print '<div class="profile">' . $account->profile_firstname . '</div>';
    print
'<div class="profile">' . $newvariable . '</div>';
   
?>

Second I created the user profile preprocessor override function in myzensubtheme/template.php thus...

<?php
   
function myzensubtheme_preprocess_user_profile(&$vars, $hook) {
       
$vars['newvariable'] = 'hello world';
    }
   
?>

Third I added the override function to the list of override hooks in myzensubtheme/template.php thus...

<?php
   
function myzensubtheme_theme(&$existing, $type, $theme, $path) {
       
$hooks = zen_theme($existing, $type, $theme, $path);
       
$hooks['user_profile'] = array('template' => 'user-profile', 'arguments' => array('form' => NULL));
        return
$hooks;
    }
   
?>

Now the weird part, when the hook is enabled the $newvariable prints, but the $account->profile_firstname does not (why?).
And the the hook is disabled the $account->profile_firstname prints but the $newvariable does not (as one would expect).

Thanks for any help.

Anyone who gives another a cold cup of water certainly will not lose his reward!

2dareis2do’s picture

This is great unless you want granular control. If so then have a look here:

http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6

Freelance Web Design and Development
---
http://www.danlobo.co.uk

fehin’s picture

subscribing

jduhls’s picture

Anyone else have this issue? Everything works great except the 'render' variable shows up empty in the template.

<?php
function themename_theme(&$existing, $type, $theme, $path) {
 
$hooks['user_login'] = array('template' => 'user-login','arguments' => array('form' => NULL));
  return
$hooks;

}
function
themename_preprocess_user_login(&$variables) {
   
$variables['dummy'] = t('hello');
   
$variables['rendered'] = drupal_render($variables['form']);
}
?>

In user-login.tpl.php...

<p><?php print $dummy; ?></p>

<div class="my-form-wrapper">
  <?php print $rendered; ?>
</div>

HELP! <div class="my-form-wrapper">... just shows up on the page with nothing inside it.

mikeyg’s picture

Same problem with rendering. I am very new to Drupal and have been having some very basic problems/questions. I'll wait for others to respond to your question but, in the meantime, you mentioned that div class="my-form-wrapper"... showed up on the page. Did you style the my-form-wrapper class or is this class a "built-in" wrapper in Drupal?

Thanks, Mike

saurabh.bhambry’s picture

I am unable to understand the need for Step2 when Drupal 6 by default provides the following template suggestions to work with : "page-user-register.tpl.php"
"page-user-login.tpl.php"
"page-user-password.tpl.php"?

Pardon me if I have missed something simple here and any explanation wud b of great help.

Thanks

Bhambry

aangel’s picture

This post is about theming the form itself whereas the page-user-login.tpl.php file allows you to theme the page that contains the form.

André Angelantoni
Founder, PerformantLabs.com

anandaperumal’s picture

Hi...

I m very new to drupal... i need a custom reg page... I m going to get three types[A,B,C] of users in my Site.... Going to get the user type in Registration page via a select box.... When i choose the user type A field1 and field2 must be listed... When i choose the user type B field3 and field4 must be listed... When i choose the user type C field5 and field6 must be listed... I need to do these changes without page refreshing ..... Anyone pls help me... :) Thanks :)

mdshields’s picture

this is a good example of a page describing functionality accompanied with a small lightweight scenario to test with. I'll probably learn more from this example than 20 other pages combined. thank you.

francis55’s picture

Might it be a good idea in some future version to decide on a few default file names (such as user_login.tpl.php, etc) and let the Drupal core find those files and display them if necessary - unless prior coding indicates otherwise? Just like it finds comment.tpl.php or node.tpl.php? Reading the comments I find I'm not the only one having trouble with this...

Francis

francis55’s picture

... but it doesn't do what I wanted, i.e hide the primary menu and heading information when not logged on.
I unchecked every single entry of the permissions of anonymous user column, uploaded a module (tobogganlogin)...

Francis

francis55’s picture

In page.tpl.php, remove unwanted sections as follows:

<?php  global $user;
if (
$user->uid): ?>

... stuff to remove...
<?php  endif; ?>

Only works at the level of overall sections, not to remove blocks inside those sections;.
Tip: if you have your own theme derived from an existing one, copy/paste the page.tpl.php file from the original theme into your theme folder before changing it.

Francis

kersha’s picture

plz help me my site has move to this site

http://7betk.net

and use this code

jrz’s picture

Hi all!
I'm using the following function to change the user registration form which only displays first name, last name and email. It works well, however when i want to add a user from the admin section i get the same form which is not what i want. I need to have the core registration form for administrators so they can set the password and allocate a role. How can I change this function so it only works for anonymous users?
function mytheme_theme($existing, $type, $theme, $path) {
return array(
'user_register' => array(
'arguments' => array('form' => NULL),
'template' => 'templates/user-register', // this is the name of the template
),
);
}

sicowan’s picture

Hi,

I have been going around in circles for a few days with this. (I am using D7)
All I want to do is alter the default text and button labels on the user registration page.

I can do this by creating a custom registration module and use myTheme_form_user_register_form_alter to change the form field values. That WORKS!! however I have found that there is a knock on effect of the admin>people>add user no longer works. In the Recent Log Messages I get:
Theme key "user_register" not found.

Lost with this! All I want to do is edit the text. Seems a lot of work to do a simple task. Anyone know a siimple solution other than keeping the default text?

S

######UPDATE######
Looks like I've worked this out.
Without using any of the above I was able to alter the registration form in the template.php with a function similar to the following:

function myTheme_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_register_form':
        if($form['#user_category'] == 'register') {
             $form['account']['name']['#title'] = t('Name');
             $form['account']['name']['#description'] = t('Instructions on adding username here');
     $form['account']['mail']['#title'] = t('E-mail address');
     $form['account']['mail']['#description'] = t('Instructions on adding email address here.');
     $form['actions']['submit']['#value'] = t('Button Says This');
        }
      break;
  }
}

No extra modules or template files. If this is not correct drupal 7 protocol then please let me know the correct solution and I can adjust my code.

Thanks,
Sicowan

NachoDuran’s picture

Hi everyone,

Last two days Ive spent too much time trying to get the way to modify my register form in Drupal 6.
I guess there are two different ways to do it:

a) Common way: using Drupal fields, like all of you guys use to do it. For this way, Ive made changes youve talk about:

- Modify template.php on my theme (im using garland). Right now, these changes are:

function garland_theme() {
return array(
'user_register' => array(
'template' => 'user-register',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_register(&$variables) {
$variables['intro_text'] = t('This is my awesome login form');
$variables['rendered'] = drupal_render($variables['form']);
}

- Create a template "user-register.tpl.php": in this file, ive put:

<?php
echo $variables['rendered'];
?>

With this, I print, the whole register form.

But I need to get field by field of the form, because I may put some buttons and texts between fields.
Is there any chance to get, i.e., the field (label and textfield) name, with something like
echo $variables['rendered']['name'];
or similar? Is there any way to separate the different fields of my register form?

b) I dont know if this is possible, but I was thinking about creating a html form, and then, relate the values we put into form fields with Drupal fields (name, email,...all of fields definied).

Its so important for me solve it. I hope you guys can help me as soon as possible. Of course Im gonna continue trying to get a solution (if I get it, I will share it).

Thank you so much ppl :)

garciac1212’s picture

How do you know what variable are avaiable and where. For node forms I know there is dsm($form) but what about forms for register?

kyleoliveira’s picture

Sicowan, that's precisely what I've been looking for. I want to override the help description on the user registration page and this seems like the simplest way.

bizaxta’s picture

I am having issues trying to customize the User Register form on my site. I had it working prior to updating my theme - I was using a sub-theme of Corolla 7.x-1.x and did not have any issues. Now I updated to Corolla 7.x-2.x, which is now a sub-theme of AdaptiveThemes 7.x-2.x and I've lost the custom registration form - it just shows the default form.

In template.php I have the following code related to these two forms:

<?php
function xring_theme() {
 
$items = array();

 
$items['user_register_form'] = array(
   
'render element' => 'form',
   
'template' => 'user-register-form',
   
'preprocess functions' => array(
      
'xring_preprocess_user_register_form'
   
),
  );   
 
$items['user_login'] = array(
   
'render element' => 'form',
   
'template' => 'user-login',
   
'preprocess functions' => array(
      
'xring_preprocess_user_login'
   
),
  );
  return
$items;
}

function
xring_preprocess_user_register_form(&$vars) {
}

function
xring_preprocess_user_login(&$vars) {
}
?>

My user-register-form.tpl.php and user-login.tpl.php files do not vary by much, but the login page (example at http://two.xringsaroundtheworld.com/user/login) shows the formatting and changes while the register page (example at http://two.xringsaroundtheworld.com/user/register) does not.

Any ideas if I have done something wrong that would cause for such a difference between these two seemingly similar things?

Thanks,
Chris

bizaxta’s picture

Realized that I had created a custom module with the following code:

<?php
function userregistration_form_user_register_form_alter(&$form, &$form_state, $form_id) {
 
$form['#theme'] = 'user_register';
}
?>

Don't remember where I came across the module code, or if it is a good way of doing this, but it worked once I changed it from 'user_register' to 'user_register_form' to match the template.php code.

mogop’s picture

Is it ti possible to create profile registration without email and password?
I'm trying to use the Subuser module where a specific role can create another subuser (with specific role and profile) but I don't need the required fields - username, email, password - can they be removed or inherit from the user that is creating the profile ?

profelm’s picture

I'm having issues with this in Drupal 7. Unfortunately, it's not performing anything on submit.

Furthermore, the user-register-form.tpl does not do anything on submission. This is ultimately what mine looks like.

<p><?php print render($intro_text); ?></p>
<div class="store-user-login-form-wrapper">
    <div class="store-user-register-form">
        <h3>Create a new account</h3>
            <form><?php print drupal_render_children($register_form); ?></form>
    </div>
    <div class="store-user-login-form">
        <h3>Log in to your account</h3>
            <form><?php print drupal_render_children($form); ?></form>
            <a href="/user/password/"><p>Forgot your password?</p></a>
    </div>
</div>
stomerfull’s picture

I have followed this tuto but not able to get it working

Im in D7 and here is mys code

in template.php in paste these code

<?php
function patrimoine_theme() {
 
$items = array();
  
 
$items['user_login_block'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'patrimoine') . '/templates',
   
'template' => 'user-login',
   
'preprocess functions' => array(
      
'patrimoine_preprocess_user_login_block'
   
),
  );
 
$items['user_register_form'] = array(
   
'render element' => 'form',
   
'path' => drupal_get_path('theme', 'patrimoine') . '/templates',
   
'template' => 'user-register-form',
   
'preprocess functions' => array(
     
'patrimoine_preprocess_user_register_form'
   
),
  );
 
  return
$items;
}

function
patrimoine_preprocess_user_login_block(&$vars) {
 
$vars['intro_text'] = t('This is my awesome login form');
}

function
patrimoine_preprocess_user_register_form(&$vars) {
 
$vars['intro_text'] = t('This is my super awesome reg form');
}
?>

and in the folder or my custom theme (sites\all\themes\patrimoine\templates)

i have create two file user-login.tpl.php and user-register-form.tpl.php with these code :

<?php
<p><?php print render($intro_text);
?>
<?php
 
print drupal_render_children($form)
?>

I have clear cache

and when i load loggin page , there is no change

Please help
?>

dalegrebey’s picture

I will look a bit closer, but straight off the bat, your print rendering doesn't look correct to me.

<?php
print render($page['intro_text']);
?>

Additionally, double check that you are not passing $variables and returning $vars.

dalegrebey’s picture

Take a look at this and see if it helps:

<?php
// FORMS: Switch _hook for different cases defined with field array key $form_id

function patrimoine_form_alter(&$form, &$form_state, $form_id) {
  switch (
$form_id) {
    case
'user_register_form':
     
$form['account']['name']['#title'] = t('Username:');
     
$form['account']['name']['#description'] = t('');
     
$form['account']['mail']['#title'] = t('Email Address:');
     
$form['account']['mail']['#description'] = t('');
     
$form['actions']['submit']['#value'] = t('Register');       
    break;
    case
'user_login_form':
    case
'user_login_block':
    case
'user_login':
     
$form['name'] = array(
       
'#type' => 'textfield',
       
'#title' => t('Username:'),
       
'#description' => t(''),
       
'#maxlength' => USERNAME_MAX_LENGTH,
       
'#size' => 15,
       
'#required' => TRUE,
      );
     
$form['pass'] = array(
       
'#type' => 'password',
       
'#title' => t('Password:'),
       
'#description' => t(''),       
       
'#maxlength' => 60,
       
'#size' => 15,
       
'#required' => TRUE,
      );
     
$form['actions']['submit'] = array(
       
'#type' => 'submit',
       
'#value' => t('Log In')
      );
     
     
$items = array();    // Create Account & Forgotten Password
     
$form['links'] = array(
        array(
'#markup' => theme('item_list', array('items' => $items))),
       
'#weight' => 0,
      );           
     
    break;
  }
}
?>
Paul Whitehead’s picture

Making create new account and forgotten password vanish.

drupalfan81’s picture

So I followed this guide line by line and got things working, but once I make these changes to my template.php file and flush caches the page doesn't finish loading and it just goes to a white screen. If I refresh the page eventually it loads and shows caches clear. My custom user-login.tpl.php is definitely loading and I can see the custom text I have added which is great, but my entire site starts to slow down and hang after I made these changes.

For example if I go to edit a node, it will display a white page after trying to load for a few seconds. Then if I refresh it will load the page. Then if I edit the page and save, it will start to load and then display a white page. I refresh again and then it finishes the save process and the page loads. Basically anything requiring loading a page requires two attempts it seems. Anyone else experiencing this issue?

The only thing I have added to my template.php file, which is what is causing this issue is:

<?php
/**
 * Registers overrides for various functions.
 *
 * In this case, overrides three user functions
 */
function newsflash_theme() {
  return array(
   
'user_login' => array(
     
'template' => 'user-login',
     
'arguments' => array('form' => NULL),
    ),
   
'user_register' => array(
     
'template' => 'user-register',
     
'arguments' => array('form' => NULL),
    ),
   
'user_pass' => array(
     
'template' => 'user-pass',
     
'arguments' => array('form' => NULL),
    ),
  );
}
?>

<?php
function newsflash_preprocess_user_login(&$variables) {
 
$variables['intro_text'] = t('Enter your username and password below to access your Account.<br />Alternatively, login with ease by clicking on the Facebook Connect button.');
 
$variables['rendered'] = drupal_render($variables['form']);
}
function
newsflash_preprocess_user_register(&$variables) {
 
$variables['intro_text'] = t('Enter your username and password below to access your Account.<br />Alternatively, login with ease by clicking on the Facebook Connect button.');
 
$variables['rendered'] = drupal_render($variables['form']);
}
function
newsflash_preprocess_user_pass(&$variables) {
 
$variables['intro_text'] = t('Enter your username and password below to access your Account.<br />Alternatively, login with ease by clicking on the Facebook Connect button.');
 
$variables['rendered'] = drupal_render($variables['form']);
}
?>

For now, I had to remove the above code from my template.php file which means Drupal is no longer loading my custom user-login.tpl.php. I would love to be able to do this. Any help would be greatly appreciated!

drupalfan81’s picture

So after a bit more playing around, I have solved this issue. I thought I would share it here in case anyone else runs into the same issue. Basically the problem was the php tags. The guide above, the way it's written can lead you into trouble.

My template.php file started with the first line being a php open tag <?php and I noticed that the file did not have a close tag. I'm not an expert at the Drupal theming engine, but I think this is what was causing issues. So if you basically just copy and paste the above code in the example into your template.php file, it could lead to issues. It shouldn't if the file had open and close tags, but I'm not sure why the end of the file is left without a closing tag. May be something specific to how the files are loaded by Drupal and the theming engine?

Anyway, since the file already had a open php tag on line 1, I just copied the code above minus the Php tags. So in essence, I am just pasting the functions. The way I had it before was that I copied and pasted everything above line by line prior to the first opening tag. So I'm guessing that since I put a closing tag in this file, it somehow caused issues. Not sure, but that's what fixed my issue. Site is working now perfectly with custom login and password reset pages. yeah!

erok415’s picture

Great stuff!

Ain't it great....!

tonie_santos’s picture

Followed the instructions to the letter, and I have no templating or customization experience. It worked!!!
Thank you so much.

raheelwp’s picture

I followed your tutorial and successfully created a custo template. I have other html elements inside my user-register.tpl.php
The problem i am facing is that what ever elements / contents are present inside my tpl file, everythings comes under a tag.

Am i making some mistake ? i want my other elements outside the form tag as its creating css issues.

Please someone provide urgent reply as i am stucked in my office task.

Thanks alot to the supportive community

samjosein’s picture

Very happy after applying this post to my Drupal site.
For those who works with a copy of 'Bartik', a blind copy paste with just a change in the 'yourtheme' will blink your eyes.
For others, nothing to say. Get shocked! :)

samjosein

bahman2216’s picture

Thanks for your article.
I did all as you said. eveythings work but messages not show any more in my custom theme.
I made user-password.tpl.php in my theme and when user enter wrong email, this just refresh current page and not show any error messages. I printed $messages in my tpl.