Hi,

I have try to implement a new custom page with customer profile data for update shipping/billing information.

I have added both fields using following code, but I got "An illegal choice has been detected. Please contact the site administrator." on country change:

(hook_menu with "drupal_get_form")

  $order = commerce_order_load($order_id);
  $form['customer']['add_customer_shipping'] = array(
    '#type' => 'container',
    '#prefix' => '<div class="main-add-1"><h3>Billing Details</h3>',
    '#suffix' => '</div>'    
  );
  $form['customer']['add_customer_billing'] = array(
    '#type' => 'container',
    '#prefix' => '<div class="main-add-2"><h3>Shipping Details</h3>',
    '#suffix' => '</div>'
  );
  
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'commerce_customer') . '/includes/commerce_customer_profile.forms.inc';
  if (isset($order->commerce_customer_shipping)&& !empty( $order->commerce_customer_shipping)) { 
    $profile_id = $order->commerce_customer_shipping['und'][0]['profile_id'];
    $profile = commerce_customer_profile_load($profile_id);
  } else {
    $profile = commerce_customer_profile_new('billing', 0);
  }
  // Ensure the owner name is accessible if the uid is set.
  if (!empty($profile->uid) && $owner = user_load($profile->uid)) {
    $profile->name = $owner->name;
  }
  if (empty($profile->created)) {
    $profile->date = format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O');
  }
  $form_state['customer_profile'] = $profile;
  field_attach_form('commerce_customer_profile', $profile, $form['customer']['add_customer_shipping'], $form_state);
  
  
  if (isset($order->commerce_customer_billing) && !empty($order->commerce_customer_billing)) { 
    $profile_id = $order->commerce_customer_billing['und'][0]['profile_id'];
    $profile = commerce_customer_profile_load($profile_id);
  } else {
    $profile = commerce_customer_profile_new('shipping', 0);
  }
  
  // Ensure the owner name is accessible if the uid is set.
  if (!empty($profile->uid) && $owner = user_load($profile->uid)) {
    $profile->name = $owner->name;
  }
  if (empty($profile->created)) {
    $profile->date = format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O');
  }
  $form_state['customer_profile'] = $profile;
  field_attach_form('commerce_customer_profile', $profile, $form['customer']['add_customer_billing'], $form_state);
  $form['customer']['account'] = array(
    '#type' => 'checkbox', 
    '#prefix' => '<div style="clear:both;"></div>',
    '#title' => t('Create an account?'),
  );
  $form['customer']['add_customer'] = array(
      '#type' => 'button',
      '#value' => t('Create new customer'),
      '#attributes' => array(
        'class' => array('transaction-btn'),
      ),
      '#ajax' => array(
        'callback' => 'commerce_order_user_js',
        'wrapper' => 'order-user-wrapper',
        'effect' => 'slide',
      ),
      '#element_key' => 'add-order-customer',
   );
  return $form;

please let me know what is incorrect when we change the country field its return "An illegal choice has been detected. Please contact the site administrator.".

Comments

dilipsingh02 created an issue. See original summary.

rszrama’s picture

Priority: Critical » Normal
Status: Active » Closed (won't fix)

Per the issue submission guidelines, we don't handle such support requests in the issue queue. Please use Drupal Answers at https://drupal.stackexchange.com.

(Also, side note: support requests should only ever use the "Normal" priority; the other priorities are for bug reports / tasks.)