11

How do I print the register and login forms on the same page?

I think I am really looking just for the form IDs, but if you've got the right render function handy it would be very appreciated.

12
print(drupal_render(drupal_get_form('user_register_form')));
print(drupal_render(drupal_get_form('user_login_block')));

See user_register_form() and user_login_block() for details. Note that user_register_form is an unusual form builder function: it redirects in some cases.

6

I took the code from LoginToboggan. This is what I got.

/**
* Implementation of hook_theme()
*/
function os_pages_theme() {
  return array(
    'os_pages_login_form' => array(
      'variables' => array(
        'register_form' => NULL,
        'login_form' => NULL,
      ),
    ),
  );
}
/**
* Logintobbogin provides the code to consolidate
* the registration page and the login page however
* it doesn't do exactly the way we want so we will 
* take the code. 
* @see http://drupal.org/project/logintoboggan
*/

 /**
 * Implementation of hook_menu_alter().
 */
function os_pages_menu_alter(&$callbacks) {
  // Kill the tabs on the login pages.
  $callbacks['user/login']['type'] = MENU_NORMAL_ITEM;
  $callbacks['user/login']['page callback'] = 'os_pages_login_page';
  $callbacks['user/register']['type'] = MENU_CALLBACK;
  $callbacks['user/register']['page callback'] = 'os_pages_login_page';
  $callbacks['user/register']['page arguments'] = array('register');
  $callbacks['user/password']['type'] = MENU_CALLBACK;
  $callbacks['user']['page callback'] = 'os_pages_login_page';
}
/**
 * Menu callback for user/login
 *   creates a unified login/registration form (without tabs)
 */
function os_pages_login_page() {
  global $user;
  if ($user->uid) {
    menu_set_active_item('user/' . $user->uid);
    return menu_execute_active_handler(NULL, FALSE);
  }
  else {
    // Title just clutters the interface...
    drupal_set_title('');
    $output = os_pages_login_form();
    return $output;
  }
}
/**
 * Builds a unified login form.
 */
function os_pages_login_form() {
  $register_form = drupal_get_form('user_register_form');
  $login_form = drupal_get_form('user_login');
  $rendered_register_form = drupal_render($register_form);
  $rendered_login_form = drupal_render($login_form);
  $variables = array(
    'login_form' => $rendered_login_form,
    'register_form' => $rendered_register_form,
  );
  $output = theme('os_pages_login_form', $variables);
  return $output;
}
/**
 * Theme function for unified login page.
 */
function theme_os_pages_login_form($variables) {

  $register_form = $variables['register_form'];
  $login_form = $variables['login_form'];
  $output = '';

  $output .= '<div class="login-form">';

  // Add the login and registration forms in.
  $output .= '<div id="register-form">' . $register_form . '</div>';
  $output .= '<div id="login-form">' . $login_form . '</div>';

  $output .= '</div>';

  return $output;
}
4

For this You need to create a page for Registration like this

page-user-register.tpl.php

And print the page contents as usual. in that page you could try render user_login_block

Additional resources

  1. http://www.trevorsimonton.com/blog/page-usertplphp-profile-php-template-drupal
  2. http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_login_block/7
4

LoginToboggan do this for you: Install it, and go to admin/config/system/logintoboggan; select "Present a unified login/registration page."

  • also if you want write your own module, you can look at its source – Mohammad Ali Akbari Apr 4 '12 at 5:34

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.