Custom page with login / register forms and custom template

Public

Warning message

We recommend you to assign at least one category to this snippet so you could easily navigate it in the future. Edit your snippet here.

MODULENAME.module

</> CopyGet raw version
php
  1. <?php
  2.  
  3. /**
  4.  * Implements HOOK_menu
  5.  *
  6.  * Establish a new link, later navigate to /admin/settings/error-reporting and redirect your 403 errors to this page.
  7.  */
  8. function MODULENAME_menu() {
  9. $items['welcome'] = array(
  10. 'title' => 'Single Page Login',
  11. 'page callback' => 'MODULENAME_single',
  12. 'page arguments' => array('user_pass'),
  13. 'access callback' => 'user_is_anonymous',
  14. 'type' => MENU_NORMAL_ITEM,
  15. );
  16.  
  17. return $items;
  18. }
  19.  
  20. /**
  21.  * Implements HOOK_theme
  22.  *
  23.  * Take control over the user login and registration pages.
  24.  */
  25. function MODULENAME_theme(&$existing, $type, $theme, $path) {
  26. return array(
  27. 'user_single_page' => array(
  28. 'arguments' => array(
  29. 'form_login' => NULL,
  30. 'form_register' => NULL,
  31. ),
  32. 'template' => 'user-single-page',
  33. ),
  34. );
  35. }
  36.  
  37. /**
  38. * Implements custom page callback for /welcome
  39. */
  40. function MODULENAME_single(){
  41. $form_login = drupal_get_form('user_login');
  42. $form_register = drupal_get_form('user_register');
  43.  
  44. return theme('user_single_page', $form_login, $form_register, $form_password);
  45. }

user-single-page.tpl.php

</> CopyGet raw version
php
  1. <?php
  2. /**
  3.  * Custom user page that combines the user login, registration, and pass forms
  4.  * Variables:
  5.  * form_login: Drupal's user login form
  6.  * form_register: Drupal's user registration form
  7.  */
  8. ?>
  9. <div id="registration_form">
  10. <h2>User Login</h2>
  11. <?php print $form_login ?>
  12. </div>
  13. <div id="login_form">
  14. <h2>Create a new user</h2>
  15. <?php print $form_register ?>
  16. </div>