2

I am trying to find out a way to add fields/modify existing fields/theme the default Drupal 7 login/registration pages in-place.

What I mean "in-place" is to find a way to not create new login/registration pages through creating "page--user--register.tpl.php" files.

I am looking for a way to add/modify/theme the mysite/user/login and mysite/user/registration pages without having to create page--user--register.

However, if overriding the hook_theme() in "template.php" and creating "page--user--register.tpl.php" file is the only way, then is there a way to have it use the same theme as the rest of the pages? I can make the custom registration page have the same theme through coyping code from "page.tpl.php" and pasting it in my "page--user--register.tpl.php" file, but this seems wrong to me.

Any help or comments are appreciated.

2

If you want add form fields to either the login or registration form(s) you will have to write custom PHP code in a module file to make any use of the fields.

The forms are just blocks on the page, and should inherit or reuse block.tpl.php pretty much everywhere. Since they are just blocks, sitewide css can target them specifically once you've made them.

The drupal login and registration system is fairly pluggable, you can "inject" your own validation code (to handle your own custom fields) and authentication pretty much however you wish.

A useful tutorial/blog post might be: http://omegadelta.net/2011/03/23/custom-authentication-with-drupal-7/

It doesn't add custom fields, but does modify the existing drupal login behavior which is what you're trying to do as well.

In your case you probably want to do something like:

  1. create a custom login/registration block in a module, it simply loads the default login or registration block as an object. Implement hook_block family of functions.
  2. hook_form_alter() the block and inject your fields and override the default user authentication validator with your own to consume your fields (similar to the linked blog posts' _geospike_user_login_form_alter() function).
  3. define a hook_menu path which outputs a page that loads/outputs your custom defined block to login or register.

Drupal can do what you want with basically a custom module and like a few hook functions. Your not creating your own user login or registration form, and your not writing your login login validators from scratch -- you are just overriding the pre-existing ones for new ones your basically telling drupal exist now via your module.

  • thanks for the help tenken. i am also wondering, if i wanted to add a drop down list of countries to the registration form, how would i do that? i have read a lot of how to add drop-down menus, but none seem to tell me how you how to detail the addition of a drop-down list for countries. thanks – chlong Mar 5 '12 at 19:18
  • You would add a "select" widget to the $form array using the drupal Form API (FAPI), api.drupal.org/api/drupal/… You could make a database table with: id, country and use db_query() to get an array of all the countries you want in your select list. – tenken Mar 5 '12 at 20:19
  • you can use the location or addressfield module to add a country to the registration form – uwe Mar 6 '12 at 13:58
2

Add this to you template.php file, where your_themename is the machine name of theme you are using

function your_themename_theme() {
  $items = array();
  // create custom user-login.tpl.php
  $items['user_login'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'your_themename') . '/templates',
    'template' => 'user-login',
    'preprocess functions' => array(
      'your_themename_preprocess_user_login'
    ),
  );
  return $items;
}

Create a user-login.tpl.php file and add this

<?php
    print drupal_render($form['name']);
    print drupal_render($form['pass']);
    print drupal_render($form['form_build_id']);
    print drupal_render($form['form_id']);
    print drupal_render($form['actions']);
?>

This is a summary of what I found on this blog post

  • Please try to include a summary with link-only answers. Link only answers are no longer useful when links break. – Citricguy Sep 25 '12 at 4:19
  • 1
    Have added the summary – Nana Akwasi Sep 25 '12 at 5:22
0

If you just want to change the theme for each page alot install Devel Themer and it can tell you a specific way to name a tpl file for your site theme to change its look/HTML/CSS specifically.

0

Drupal 7

Add this code to your template.php in your theme directory.

    function yourtheme_theme() {
      return array(
        'user_login' => array(
          'template' => 'user-login',
          'arguments' => array('form' => NULL),
        ),
      );
    }

    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'
        ),
      );
      return $items;
    }

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

Create a file in your theme's "templates" folder called user-login.tpl.php.

Add this code and change "yourtheme" to your theme name.

 <?php print drupal_render_children($form) ?>

Clear you cache.

Source (Where you can find details on how to do this for user-register-form, user-password-form, and Drupal 6) https://drupal.org/node/350634

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.