4.7.x user.module user_register_submit($form_id, $form_values)
5.x user.module user_register_submit($form_id, $form_values)
6.x user.module user_register_submit($form, &$form_state)
7.x user.module user_register_submit($form, &$form_state)

Submit handler for the user registration form.

This function is shared by the installation form and the normal registration form, which is why it can't be in the user.pages.inc file.

See also

user_register_form()

1 string reference to 'user_register_submit'
user_register_form in modules/user/user.module
Form builder; the user registration form.

File

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

Code

function user_register_submit($form, &$form_state) {
  $admin = $form_state['values']['administer_users'];

  if (!variable_get('user_email_verification', TRUE) || $admin) {
    $pass = $form_state['values']['pass'];
  }
  else {
    $pass = user_password();
  }
  $notify = !empty($form_state['values']['notify']);

  // Remove unneeded values.
  form_state_values_clean($form_state);

  $form_state['values']['pass'] = $pass;
  $form_state['values']['init'] = $form_state['values']['mail'];

  $account = $form['#user'];

  entity_form_submit_build_entity('user', $account, $form, $form_state);

  // Populate $edit with the properties of $account, which have been edited on
  // this form by taking over all values, which appear in the form values too.
  $edit = array_intersect_key((array) $account, $form_state['values']);
  $account = user_save($account, $edit);

  // Terminate if an error occurred during user_save().
  if (!$account) {
    drupal_set_message(t("Error saving user account."), 'error');
    $form_state['redirect'] = '';
    return;
  }
  $form_state['user'] = $account;
  $form_state['values']['uid'] = $account->uid;

  watchdog('user', 'New user: %name (%email).', array('%name' => $form_state['values']['name'], '%email' => $form_state['values']['mail']), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));

  // Add plain text password into user account to generate mail tokens.
  $account->password = $pass;

  // New administrative account without notification.
  $uri = entity_uri('user', $account);
  if ($admin && !$notify) {
    drupal_set_message(t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
  }
  // No e-mail verification required; log in user immediately.
  elseif (!$admin && !variable_get('user_email_verification', TRUE) && $account->status) {
    _user_mail_notify('register_no_approval_required', $account);
    $form_state['uid'] = $account->uid;
    user_login_submit(array(), $form_state);
    drupal_set_message(t('Registration successful. You are now logged in.'));
    $form_state['redirect'] = '';
  }
  // No administrator approval required.
  elseif ($account->status || $notify) {
    $op = $notify ? 'register_admin_created' : 'register_no_approval_required';
    _user_mail_notify($op, $account);
    if ($notify) {
      drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
    }
    else {
      drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.'));
      $form_state['redirect'] = '';
    }
  }
  // Administrator approval required.
  else {
    _user_mail_notify('register_pending_approval', $account);
    drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your e-mail address.'));
    $form_state['redirect'] = '';
  }
}

Comments

overbythere’s picture

Should you want to redirect after registration, then the following needs to be added as a custom modile:

function custom_form_alter(&$form, $form_state, $form_id) {
	if($form_id=='user_register_form') { $_GET['destination'] = 'node/yournode'; }
}
proxiss’s picture

Does the redirect by setting $_GET work for you?
Not for me.

mpnordland’s picture

Overriding the submit handler in the hook_form_alter should work. Just replace $form['#submit'] with your own submit function that calls user_register_submit and then sets $form_state['redirect'] to the path you want.

mpnordland’s picture

Better yet

function custom_form_alter(&$form, $form_state, $form_id) {
	if($form_id=='user_register_form') { 
          $form['#submit'] = array('custom_form_submit');
        }
}

function custom_form_submit($form, &$form_state){
    user_register_submit($form, $form_state);
    $form_state['redirect'] = 'node/yournode';
}