| 5 user.module | user_register_submit( |
| 6 user.module | user_register_submit($form, &$form_state) |
| 7 user.module | user_register_submit($form, &$form_state) |
| 8 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
1 string reference to 'user_register_submit'
File
- modules/
user/ user.module, line 3751 - 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'] = '';
}
}
Login or register to post comments
Comments
Where does this go? I just need to email
Here is what I have:
<?php
/**
* Implements hook_menu()
*/
function zohocrm_menu() {
//drupal_set_message("Hello!");
$items['zohocrm'] = array(
'title' => t('Create a user from the Zoho CRM'),
'page callback' => 'create_user_zohocrm',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function create_user_zohocrm() {
// Get Variables from POST and see if they display
$name = $_REQUEST['fname'] . " " . $_REQUEST['lname'];
if (!user_load_by_mail($_REQUEST['email'])) {
$account = new stdClass;
$account->is_new = TRUE;
$account->name = $name;
$account->pass = user_password();
$account->mail = $_REQUEST['email'];
$account->init = $_REQUEST['email'];
$account->status = TRUE;
$account->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
$account->timezone = variable_get('date_default_timezone', '');
user_save($account);
// Send new user no approval required email
_user_mail_notify('register_no_approval_required', $account);
}
return "SUCCESS";
}
?>
It creates the account when a querystring loads the data to it, but it won't send the email letting them know even though I have the code _user_mail_notify.
How can I create a user programatically using a POST from an external page, securely, and send them an e-mail?
Jacob