Monday 22 March 2010

How to change User Registration form

first take view source of your registration page and find form_id.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

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

);
}

function garland_preprocess_user_register(&$vars)
{
/*print '
';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];

$tempVar['name']['#title'] = 'User Name';
$tempVar['submit']['#value'] = 'Create Account';

$vars['username'] = drupal_render($tempVar['name']);
$vars['useremail'] = drupal_render($tempVar['mail']);
$vars['submit_button'] = drupal_render($tempVar['submit']);
$vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-register.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username; // print the password field
    ?>   
  </div>
  <div class="field">
    <?php
     print $useremail; // prints the username field
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

so using the above way, you can change your user registration page template.

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

No comments:

Post a Comment