My Drupal 7 site utilizes the email_registration and logintobbagan modules. It works fine to register users with just their e-mail address. However, on a separate page I am using a newsletter subscribe form called 'news_subscribe' which is of the following form:
function news_subscribe_form($form, &$form_state) {
$user = $GLOBALS['user']->mail;
$email = "";
if(!empty($user))
{
$email = $user;
}
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#required' => TRUE,
'#default_value' => $email,
'#size' => 20,
'#maxlength' => 20,
'#element_validate' => array('news_subscribe_email_element_validate'),
);
$form['id'] = $id;
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Subscribe!'),
);
return $form;
}
By default this then submits the data to the drupal databases and saves the values for the given user if they are already registered in our system via hook_form_submit().
function news_subscriptions_form_submit($form, &$form_state) {
//Get the values
$email = $form_state['values']['email'];
$id = $form_state['build_info']['args'][0];
$uid = $GLOBALS['user']->uid;
//Get the database information
$collection = variable_get('mongo_user_preferences_collection',DEFAULT_USER_PREFERENCES_COLLECTION);
$savedarrayname = variable_get('mongo_saved_data_array',DEFAULT_SAVED_DATA_ARRAY);
//Generate the conditions and queries
$where = array("uid"=>intval($uid));
$query = array($savedarrayname=>$id);
//Insert the data into the datbase
upsertData($where,$query,$collection,$database=NULL);
}
If the user is not currently registered in the system I need to first automatically register them and then retrieve their user id. I know that normally I can use a function such as
$new_user = array(
'name' => 'JohnDoe',
'mail' => '[email protected]',
'pass' => 'password123',
'status' => 1,
'field_custom_first_name' => array(LANGUAGE_NONE => array(array('value' => 'John'))),
'access' => REQUEST_TIME,
'roles' => array(), // No other roles than Authenticated
);
user_save(NULL, $new_user);
However, I want to integrate it with the current setup which requires just an email address, auto generates a password and then sends a mail to the user with a temporary login link where they can change the password. This is the current setup on the user registration form. I have been looking for a hook into the email_registration module but cannot find one. Can anyone provide some insight?
Basically I am trying to register a user from a non-registration form (if they are not already registered). I then need to retrieve their assigned uid which is used in subsequent post-processing.