Customized User Registration form with Profile fields I'm missing something core to how user registration forms are customized and the data is added to the database and I'm hoping to get a workflow.

I have created about a dozen Profile fields, textareas, radio buttons, select lists, etc.

I have written a module to do a form_alter, and in that module I have laid out fieldsets and containers so that everything is neat and orderly.  For example, for Home Information I have this:

$form['hi'] = array(
    '#type' =&gt; 'fieldset',
    '#prefix' =&gt; '&lt;div id="hi_cont"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#title' =&gt; t('Home Information'),
    );

    $form['hi']['hic'] = array(
    '#type' =&gt; 'container',
    '#prefix' =&gt; '&lt;div id="hic"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',

    );

    $form['hi']['hic']['left'] = array(
    '#type' =&gt; 'container',
    '#prefix' =&gt; '&lt;div id="hic_left"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',

    );

    $form['hi']['hic']['right'] = array(
    '#prefix' =&gt; '&lt;div id="hic_right"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#type' =&gt; 'container',

    );


and then I have this to display Profile fields that are relevent to Home Information:

$form['hi']['hic']['right']['profile_memberlist']['field_home_phone'] = $form['profile_memberlist']['field_home_phone'];
$form['hi']['hic']['right']['profile_memberlist']['field_home_phone']['#maxlength'] = 16;
$form['hi']['hic']['right']['profile_memberlist']['field_home_phone']['#size'] = 13;
$form['hi']['hic']['right']['profile_memberlist']['field_home_phone']['#title'] = t('Phone');
$form['hi']['hic']['right']['profile_memberlist']['field_home_phone']['#description'] = t('Enter your phone number');
$form['hi']['hic']['left']['profile_memberlist']['field_first_name'] = $form['profile_memberlist']['field_first_name'];
$form['hi']['hic']['left']['profile_memberlist']['field_first_name']['#maxlength'] = 16;
$form['hi']['hic']['left']['profile_memberlist']['field_first_name']['#size'] = 13;
$form['hi']['hic']['left']['profile_memberlist']['field_first_name']['#title'] = t('First Name YO');
$form['hi']['hic']['left']['profile_memberlist']['field_first_name']['#description'] = 'HEY THERE';


Now when I view the registration form, I see first all my generic Profile fields, PLUS the elements created from the above. I thought that unsetting the profile_memberlist was the way to go, but it turns out that while the user is created the Profile fields do not get saved this way.

My Submit is something like this:

$form['#submit'][] ='all_data_form_submit';


the actual function:

function all_data_form_submit($form, &amp;$form_state) {
drupal_set_message('&lt;pre&gt;' . print_r($form_state['values'],TRUE) . '&lt;/pre&gt;');


$new_user = array(
'name' =&gt; $form_state['values']['name'],
'pass' =&gt; user_password(),
'mail' =&gt; $form_state['values']['mail'],
'init' =&gt; $form_state['values']['mail'],
'status' =&gt; 0,
'access' =&gt; REQUEST_TIME,
  'field_first_name' =&gt; array(LANGUAGE_NONE =&gt; array(array('value' =&gt; $form_state['values']['field_first_name']))),
  'field_last_name' =&gt;  array(LANGUAGE_NONE =&gt; array(array('value' =&gt; $form_state['values']['field_last_name']))),

);




$form_state['redirect'] = array(
'node/31890',

array(
  'query' =&gt; array(
    'foo' =&gt; 'bar',
  ),
  'fragment' =&gt; 'baz',
 ),
);


$account = user_save(null,$new_user);


}


But that ends with a DATA INTEGRITY error on submit, because apparently user_save is being called twice?  I remove the user_save and the user is created, but none of the Profile fields get added to the database.

What has worked for me is when both the unstyled and the styled form elements are shown, and I don't use a custom submit handler, the Profile data is saved.

My question: how do I display the styled and neatly organized form elements only, and have the data entered through them get saved to the database?
I believe you're looking for hook_user_presave().

This hook is called directly before the user is saved and the $edit arg will contain all of your form values.

As an alernative, you may look at the Profile2 module