This is for Drupal 7. I am trying to write my first real custom module but I'm running into some difficulty and I'm just not sure how to look for my answers.
I've created a new entity for my module (with Entity API) with a corresponding table in the database. I need to add records to this table upon new user registration. I've used Form API to add a new field to the user registration form but I'm not quite sure the best way to do the next step. When the registrant submits the form, I would like all the regular Drupal registration stuff to happen, but I would like to intercept this one field and have its data go to the table I've created for my entity.
Here's what I have in the .module file of my custom module (the part concerning the registration form):
/**
* Implement hook_form_user_register_form_alter()
*/
function my_module_form_user_register_form_alter(&$form, &$form_state, $form_id){
//add my module textbox to the registration form
$form['my_module_field'] = array(
'#type' => 'textfield',
'#title' => t('My Module field'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'New Submit Button',
'#submit' => array('my_module_form_submit'),
);
unset($form['actions']);
}//end my_module_form_user_register_form_alter
/* Custom Submit handler */
function my_module_form_submit($form, $form_state){
db_insert('my_entity_table')->fields(array(
'my_entity_item' => $form_state['values']['my_module_field'],
))->execute();
drupal_set_message('Your information has been saved.');
}//end my_module_form_submit
This is working fine to get my special field in my special table. But the user is not created. I suppose I could do it manually (like enter the other information into the appropriate users table and everything) but obviously I would rather not do that manually.
I feel that I must be missing something obvious here but I'm not having any luck searching for it. I am self-taught in the little I know of programming and Drupal.
Is there a way for me to just jump in to the regular submission handler and say, "hey, put my field here instead!"?
Thank you for your time.