description

These snippets allow you to override the default user registration layout using a custom user_register.tpl.php.

If you want to customize the full page layout, click through to the customizing the login, registration and request password full page layout handbook page.

step 1 of 2

In a text editor like notepad.exe, create a file called template.php using the the following snippet. If you already have a template.php file, simply add it to your existing one (remembering to omit the opening and closing PHP tags if you're adding it to an existing template.php file, i.e. <?php and ?).

<?php
 /**
   * This snippet catches the default login form and looks for an
   * user_register.tpl.php file in the theme folder
   */

function phptemplate_user_register($form) {
    return _phptemplate_callback('user_register', array('form' => $form));
}
?>

step 2 of 2

  1. In a text editor create a new text file and paste the following snippet into it. Save the file with the filename user_register.tpl.php
  2. Edit the style sheet classes and content to suit
  3. Upload your edited user_register.tpl.php to your active theme folder

For use with Drupal 4.7.x

<div class="registration_form">
<p>Extra instructions or content can go here, just above the registration form</p>
<?php
    print_r(form_render($form)); // this displays the login form.
?>
<p>Extra instructions or content can go here, just below the registration form</p>
</div>

For use with Drupal 5.x

<div class="registration_form"><p>Extra instructions or content can go here, just above the registration form</p>
<?php
    print_r(drupal_render($form)); // this displays the login form.
?>
<p>Extra instructions or content can go here, just below the registration form</p>
</div>

Style sheet reference

For controlling how your registration form looks using your style sheet, this is what the rendered registration form HTML and class names are by default:

<form action="/user/register"  method="post" id="user-register">
<div class="form-item">
 <label for="edit-name">Username: <span class="form-required" title="This field is required.">*</span></label>
 <input type="text" maxlength="60" name="name" id="edit-name"  size="60" value="" class="form-text required" />
 <div class="description">Your preferred username; punctuation is not allowed except for periods, hyphens, and underscores.</div>
</div>
<div class="form-item">
 <label for="edit-mail">E-mail address: <span class="form-required" title="This field is required.">*</span></label>
 <input type="text" maxlength="64" name="mail" id="edit-mail"  size="60" value="" class="form-text required" />
 <div class="description">A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.</div>
</div>
<input type="hidden" name="form_id" id="edit-user-register" value="user_register"  />
<input type="submit" name="op" id="edit-submit" value="Create new account"  class="form-submit" />

notes

  • If you have an even more advanced snippet that has been tested, please add a child page to this handbook page
  • This snippet was tested with Drupal 5.x (June 24th 2007) by Dublin Drupaller (Note: If you have the locale.module enabled you may need to refresh your search_index by editing any text string related to the user page before your changes take effect, such as 'password'. )
  • More advanced snippets to follow

Comments

DesignWork’s picture

Hi Dublin Drupaller,

I found a way that is maybe easier than creating a tpl.php.

Just override the form in your theme like this.

function phptemplate_user_register($form) {
$output = '';
$output .= drupal_render($form['captcha']);
$output .= drupal_render($form['name']);
$output .= drupal_render($form['mail']);
$output .= drupal_render($form['pass']);
$output .= drupal_render($form['status']);
$output .= drupal_render($form['notify']);
$output .= drupal_render($form['submit']);
$output .= drupal_render($form);
return $output;
}

I wanted to change only the order of the fields. you may alter div with classes for themeing like


function phptemplate_user_register($form) {
$output = '';
$output .= drupal_render($form['name']);
//extra fields not used in normal user_register form
$output .= '

';
//end extra fields
$output .= drupal_render($form['mail']);
$output .= drupal_render($form['pass']);
$output .= drupal_render($form['captcha']);
$output .= drupal_render($form['status']);
$output .= drupal_render($form['notify']);
$output .= drupal_render($form['submit']);
$output .= drupal_render($form);
return $output;
}

actually you can do this with every from in drupal 5.x.

Cheers

Dirk

indiapoly’s picture

If you need to add more HTML and flexibility then i think you should go for a custom .tpl.php

<div  class="stepBox">
        <div>
            <?php  print drupal_render($form); ?>                                                     
        </div>                                                                                                
</div>                    
<script tpe="text/javascript">
/***
Some quick scripts for registration page can go here :-)
**/
</script>                   

indiapoly- India user Group

Trulala’s picture

6* version drupal?

jho1086’s picture

subcribe

jho1086’s picture

is this work with drupal version 5.7

Because I try it to put to my template.php and include to my .tpl.php file but the (registration) form field did not display...

Any reply are greatly appreciated. Thanks.

vishun’s picture

Well, I am definitely glad I stumbled onto this thread, as it provided an extension to a custom hack that i found that allows you to actually customize each item of a form. The previous was for node submission forms, but with the template.php hack contained on here works -great- in conjunction with the following, which will allow you to change the weight, text value, add html/text before and after each field, and more.

user_register.tpl.php

<?php
//changes the Personal Information groups weight, so that it floats down the page
$form['Personal Information']['#weight'] = 10;

//change the actual Personal Information text/title to whatever you want
$form['Personal Information']['#title'] = 'My New Title'; //previously Personal Information

//add text or html before and/or after a group or other item
$form['Personal Information']['#prefix'] = 'you can put text or html here to enclose a group';
$form['Personal Information']['#suffix'] = 'you can put text or html here to at the end of a group';

//group is capable of being collapsed (not sure if this works or not)
$form['Personal Information']['#collapsible'] = 1;

//group is collapsed by default
$form['Personal Information']['#collapsed'] = 1;

//change the title of an item in a group
$form['Personal Information']['profile_firstname']['#title'] = 'Your First Name'; //previously First Name

//and so on, and so forth... to figure out what you can override, uncomment the line below

//uncomment the following line to see the whole submission form output to see what you can change. to see the output in a formatted manner, view the source of the page
//print_r($form);
print drupal_render($form);
?>
theropodx’s picture

I found with drupal 6 I didn't even need the theme code listed above. Just copy your page template file as page-user-register.tpl.php and edit as desired! Works fine.

nitz_09’s picture

Hey theropodx,
how do u have changed in drupal 6?
so if you changed the form then plz let me know...bcz i want to do the same. but i can't find for drupal 6......

theropodx’s picture

Find the file named "page.tpl.php" under your theme directory (eg sites/all/themes/yourtheme/) and make a copy of it. Name the copy page-user-register.tpl.php and edit it as desired. Worked for me!

theropodx’s picture

Note that you can't edit the actual form this way, but in my case I just needed to add a statement above the form warning users not to use certain words in their usernames.

zanlus’s picture

The form! It's about the form! How does one edit the form?

jibninjas’s picture

You need to edit the template.php file. This video shows you how to do that. It worked perfect for me.

http://drupaldojo.com/session/fine-tuning-ui-theming-forms-drupal-60

EthanT’s picture

This did not show me how to do that.

Ethan Teague

gekido’s picture

This page is probably the most useful of the dozens of pages that I've found that claim to provide tutorials about how to theme the user / registration form:

http://drupal.org/node/350634

So frustrating that something so simple is so mind-boggling obtuse

greta_drupal’s picture

Another way:
If you merely want to add text to the registration form (such as notice about usernames, whitelisting of from email address, etc.), you can create a Block and set it to show _only_ on the user/register page. Much more flexible than changing template file.

sledge81’s picture

Hello,

Wanted to share a tip with other newbies like me looking for customizing the form.

I simply created a copy of page.tpl.php and renamed it to page-user-register.tpl.php

I went to my user/register page and right clicked and opened the source. Copy/Paste helped and i was able to really customize the form.

One problem with this though is that if I update my form (add more fields) in the future, this customized page doesn't update.

what i'd like to know is are there variables that I can drop into the custom tpl file instead of hardcoding them?

Thanks.

DeeZone’s picture

Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 ->
http://drupal.org/node/350634

Vemma-1’s picture

Wondering how to do on D7? Thx.