I have written a custom module to add a simple form step before the user resistration form. I have the following which adds some custom fileds in to the registration form
function join_form_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register_form') {
//lots of extra fields
}
}
I have also created an install script to create a new table in the DB so that I didn't have to mess with the default users table. Currently everything works, except saving the custom data to my new table.
Here is my custom submit function
function join_form_form_submit($form, &$form_state) {
$form_id = $form_state['input']['form_id'];
switch($form_id) {
case 'join_form_form':
//
break;
case 'user_register_form':
$date = new DateTime();
$data = array(
'username' => $form_state['values']['name'],
'email' => $form_state['values']['mail'],
'title' => $form_state['values']['title'],
'first_name' => $form_state['values']['first_name'],
'last_name' => $form_state['values']['last_name'],
'gender' => $form_state['values']['gender'],
'dob' => $form_state['values']['dob'],
'address_1' => $form_state['values']['address_1'],
'address_2' => $form_state['values']['address_2'],
'address_3' => $form_state['values']['address_3'],
'country' => $form_state['values']['country'],
'county_state' => $form_state['values']['county_state'],
'postcode' => $form_state['values']['postcode'],
'contact_pref' => $form_state['values']['contact'],
'created' => $date->format('Y-m-d H:i:s')
);
user_save(drupal_anonymous_user(), $data);
drupal_set_message(t('Good here.'));
db_insert('registrations')
->fields(array(
'title' => $form_state['values']['title'],
'first_name' => $form_state['values']['first_name'],
'last_name' => $form_state['values']['last_name'],
'gender' => $form_state['values']['gender'],
'dob' => $form_state['values']['dob'],
'address_1' => $form_state['values']['address_1'],
'address_2' => $form_state['values']['address_2'],
'address_3' => $form_state['values']['address_3'],
'country' => $form_state['values']['country'],
'county_state' => $form_state['values']['county_state'],
'postcode' => $form_state['values']['postcode'],
'contact_pref' => $form_state['values']['contact'],
'created' => $date->format('Y-m-d H:i:s')
))->execute();
//empty session data
unset($_SESSION['name']);
unset($_SESSION['email']);
break;
}
}
Is it possible for me to override the default reg process to save the user normally and then save the data into my custom table and then define a redirect? Am I heading in the right direction?