Text field will not save after moving it from commerce billing profile to account fieldset in checkout I am having difficulty moving a text field from the commerce billing profile entity to the account fieldset on the checkout page. No matter what I do the text field is not saved after moving it back in the custom validate function. Is there something that I'm missing?

/**
 * Implements hook_form_alter() from checkout page.
 */
function example_form_commerce_checkout_form_checkout_alter(&amp;$form, &amp;$form_state, $form_id) {

  // Move phone number field from billing profile to account fieldset
  $form['account']['phone_number'] = $form['customer_profile_billing']['field_customer_phone_number'];
  unset($form['customer_profile_billing']['field_customer_phone_number']);

  // Declare custom validate and submit functions
  $form['buttons']['continue']['#validate'][] = 'example_checkout_form_validate'; 
  $form['buttons']['continue']['#submit'][] = 'example_checkout_form_submit';
}

/**
 * Custom checkout form validate function
 * @param type $form
 * @param type $form_state
 */
function example_checkout_form_validate($form, &amp;$form_state) {

  // Move field back to billing profile
  $form_state['values']['customer_profile_billing']['field_customer_phone_number'] = $form_state['values']['account']['phone_number'];
  unset($form_state['values']['account']['phone_number']);
}


EDIT: I tried moving the text field back to commerce profile in a custom submit handler as shown below, but I still can't get it it work.

/**
 * Custom checkout form submit function
 * @param type $form
 * @param type $form_state
 */
function example_checkout_form_submit($form, &amp;$form_state) {

  // Move field back to billing profile
  $form_state['values']['customer_profile_billing']['field_customer_phone_number'] = $form_state['values']['account']['phone_number'];
  unset($form_state['values']['account']['phone_number']);
}


I want to move this field, which is for the customer's phone number, on the checkout page for aesthetic purposes. In the current workflow the shipping address is shown first followed by the billing address. Since the phone number field is attached to the billing profile, it looks strange when "My Billing information is the same as my Shipping information." is check as shown below.



This is the last part of the checkout page redesign. I am so close to finishing it. Any help would be much appreciated.

Thanks
Paul

EDIT

I was finally able to figure this out with the help of Ryan Szrama and http://www.drupalcommerce.org/questions/3711/saving-customer-profile-field. Thank you guys.

function example_checkout_form_submit($form, &amp;$form_state) {
  $order = $form_state['order'];
  $phone = $form_state['values']['account']['phone_number'][LANGUAGE_NONE][0]['value'];
  $po = $form_state['values']['account']['po_number'][LANGUAGE_NONE][0]['value'];

  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

  // get profile id
  $profile_id = $order_wrapper-&gt;commerce_customer_billing-&gt;profile_id-&gt;value();

  // load customer profile
  $profile = commerce_customer_profile_load($profile_id);
  if ($profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile)) {
    // set the value of the field and save the profile
    $profile_wrapper-&gt;field_customer_phone_number-&gt;set($phone);
    $profile_wrapper-&gt;field_customer_po_number-&gt;set($po);
    $profile_wrapper-&gt;save();
  }
  unset($form['account']['phone_number']);
  unset($form['account']['po_number']);
}
Unfortunately, you can't move this and have it continue working as normal. Entity form submission depends on a specific "tree" hierarchy in the submitted field values, and moving it like this disrupts that. Thus when the customer profile information is saving, your custom textfield is just invisible.

If you really need to move this, then you should add a custom submit handler that populates the customer profile as before.