function user_register

You are here

4.6 user.module user_register($edit = array())
4.7 user.module user_register()
5 user.module user_register()
6 user.module user_register()

Form builder; The user registration form.

See also

user_register_validate()

user_register_submit()

Related topics

9 string references to 'user_register'
openid_authentication in modules/openid/openid.module
Authenticate a user or attempt registration.
openid_form_alter in modules/openid/openid.module
Implementation of hook_form_alter : adds OpenID login to the login forms.
theme_comment_post_forbidden in modules/comment/comment.module
Theme a "you can't post comments" notice.
user_admin in modules/user/user.admin.inc
Page callback: Generates the appropriate user administration form.
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site.

... See full list

File

modules/user/user.module, line 2458
Enables the user registration and login system.

Code

function user_register() {
  global $user;

  $admin = user_access('administer users');

  // If we aren't admin but already logged on, go to the user page instead.
  if (!$admin && $user->uid) {
    drupal_goto('user/' . $user->uid);
  }

  $form = array();

  // Display the registration form.
  if (!$admin) {
    $form['user_registration_help'] = array(
      '#value' => filter_xss_admin(variable_get('user_registration_help', '')),
      
      // Ensure that user registration help appears above profile fields.
      '#weight' => -20,
    );
  }

  // Merge in the default user edit fields.
  $form = array_merge($form, user_edit_form($form_state, NULL, NULL, TRUE));
  if ($admin) {
    $form['account']['notify'] = array(
      '#type' => 'checkbox',
      '#title' => t('Notify user of new account'),
    );
    // Redirect back to page which initiated the create request;
    // usually admin/user/user/create.
    $form['destination'] = array(
      '#type' => 'hidden',
      '#value' => $_GET['q'],
    );
  }

  // Create a dummy variable for pass-by-reference parameters.
  $null = NULL;
  $extra = _user_forms($null, NULL, NULL, 'register');

  // Remove form_group around default fields if there are no other groups.
  if (!$extra) {
    foreach (array(
      'name',
      'mail',
      'pass',
      'status',
      'roles',
      'notify',
    ) as $key) {
      if (isset($form['account'][$key])) {
        $form[$key] = $form['account'][$key];
      }
    }
    unset($form['account']);
  }
  else {
    $form = array_merge($form, $extra);
  }

  if (variable_get('configurable_timezones', 1)) {
    // Override field ID, so we only change timezone on user registration,
    // and never touch it on user edit pages.
    $form['timezone'] = array(
      '#type' => 'hidden',
      '#default_value' => variable_get('date_default_timezone', NULL),
      '#id' => 'edit-user-register-timezone',
    );

    // Add the JavaScript callback to automatically set the timezone.
    drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    Drupal.setDefaultTimezone();
  });
}', 'inline');
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Create new account'),
    '#weight' => 30,
  );
  $form['#validate'][] = 'user_register_validate';

  return $form;
}

Comments

Note that the above code is missing the last few lines of user_register(). You can see them in the full user.module listing http://api.drupal.org/api/drupal/modules--user--user.module/6/source and I include them below (starting from the drupal_add_js()).

<?php
   
// Add the JavaScript callback to automatically set the timezone.
   
drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    Drupal.setDefaultTimezone();
  });
}'
, 'inline');
  }

 

$form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
 
$form['#validate'][] = 'user_register_validate';

  return

$form;
}
?>

See also: #818296: Parser getting confused by JS? which when deployed will fix this.