Profile2 regpath move account email field, into profile2 form and handle submit I have a profile2 regpath displaying my profile2 form, and the system default account registration form below it. I need to move the account email field up into the container with the profile2 fields.



I have altered the form and moved the account mail field from the account form, into the profile form, and I have created an additional validation handler to try insert the mail value into the $form_state value so the user_account_form_validate() doesn't choke on a missing ['mail'] index:

function si_student_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  global $user;
  // remove fieldgroups and tabs for anonymous users, e.g. /student/register
  if($user-&gt;uid == 0) {
    // move email field from account to below profile2 name fields
    $email = $form['account']['mail'];
    unset($form['account']['mail']);
    // add email to profile
    $form['profile_student']['mail'] = $email;
    // change weights
    $form['profile_student']['mail']['#weight'] = 3;

    // custom validation handler to inject mail value into 
    // correct place in $form_state['values'] array
    $form['#validate'][] = '_si_student_register_anonymous_validate';
    //dpm($form);
  }
}

function _si_student_register_anonymous_validate($form, &amp;$form_state) {
  $form_state['values']['mail'] = $form_state['values']['profile_student']['mail'];
}


However this isn't working, and I get the following:



Any ideas? I'm not sure I'm taking the right approach here. Thanks
Found solution here: move fields in the user profile form in fieldsets

But I also needed to add the submitted $form_state mail value, back to the location it would have originally existed.

function si_student_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  global $user;
  // remove fieldgroups and tabs for anonymous users, e.g. /student/register
  if($user-&gt;uid == 0) {

    // move email field from account to below profile2 name fields
    $email = $form['account']['mail'];
    unset($form['account']['mail']);
    // add email to profile
    $form['profile_student']['mail'] = $email;
    // change weights
    $form['profile_student']['mail']['#weight'] = 3;

    // replace original validation handler
    $form['#validate'][0] = '_si_student_register_anonymous_validate';
  }
}

function _si_student_register_anonymous_validate(&amp;$form, &amp;$form_state) {

  // add field back to account
  $form['account']['mail'] = $form['profile_student']['mail'];
  // add submitted value from profile2 submission handler into default mail value location
  $form_state['values']['mail'] = $form_state['values']['profile_student']['mail'];
  // call validation function with update field
  user_account_form_validate($form, $form_state);

}