Let us say you want to collect a bit more information about users during registration. For example, instead of just username and email, I also want place of residenc. How do I collect and store this data per user? At the end of the day I want to end up with place of residence of each user by doing an easy query.
PS: Currently, I have added extra fields to the form user_register_form
, but I don't know how to associate this data with my new user because I don't have the new user id.
What is the right approach? Because I think this should be a trivial Drupal exercise, but am sweating :)
.
I am using Drupal 7.1.
// implements hook_form_alter()
// user-register-form id the id in html but id that works in php is user_register_form
function mymodule_form_alter(&$form, &$form_state, $form_id) {
switch($form_id) {
case 'user_register_form':
$form['placeofresidence']= array(
'#title'=>'where do you stay?',
'#type' => 'textfield',
'#required' => true,
);
$form['#submit'][]='mycustommodule_submit'; //add to callback submit list
break;
}
}
function mycustommodule_submit($form, &$form_state) {
$stayswhere=$form_state['values']['placeofresidence']; // how do I associate this with new user?
}