How to theme user login form in a drupal site?
How to theme user login form in a drupal site? Let's say, we need to alter the descriptions in user login form. Following eaxmple will add new description to the title and password fields:
1. Add the following function in templete.php file. This function is used to register theme implementation of user module. You can find more on this in this url http://api.drupal.org/api/function/hook_theme/6.
function THEME_theme() {
return array(
'user_login' => array(
'template' => 'user-login',
'arguments' => array('form' => NULL),
),
);
}You need to replace THEME with your theme name. So, if your theme name is garland, then the function will be garland_theme().
2. Add following function in your template.php file.
function THEME_preprocess_user_login(&$variables) {
$variables['form']['name']['#description'] = t('This is new description for username text box.');
$variables['form']['pass']['#description'] = t('This is new description for password text box.');
$variables['rendered'] = drupal_render($variables['form']);
}In the above function replace THEME with your theme name like you did in step 1. Through this function you can alter other form information also. Let's say, you want to alter the user name fields label. You need to add following code in the above function:
$variables['form']['name']['#title'] = t('My New Title.');So, the overlall function will look like:
function THEME_preprocess_user_login(&$variables) {
$variables['form']['name']['#description'] = t('This is new description for username text box.');
$variables['form']['pass']['#description'] = t('This is new description for password text box.');
$variables['form']['name']['#title'] = t('My New Title.').
$variables['rendered'] = drupal_render($variables['form']);
}function drupal_render will render the $variable['form'] array.
3. Now in your theme directory create a file as user-login.tpl.php and put following code there. You can use your custom css stuff through this tpl file.
<div class="user-form-wrapper">
<?php print $rendered; ?>
</div>4. After putting all the code, don't forget to clear your theme cache.





There are no comments for "How to theme user login form in a drupal site?".
Post new comment