Customizing the user registration form

Last modified: June 20, 2009 - 18:35

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

theme function

DesignWork - August 29, 2008 - 11:42

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 .= ';
$output .= drupal_render($form['field_first_name']);
$output .= drupal_render($form['field_last_name']);
$output .= drupal_render($form['field_talents']);
$output .= drupal_render($form['field_genres']);
$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

If you really need to add styles and more custom HTML..

indiapoly - January 31, 2009 - 20:29

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

 
 

Drupal is a registered trademark of Dries Buytaert.