I am using Drupal 7.2 and Drupal Commerce which requires Addressfield installed.

On the customer profile form, the address form loads properly but once I choose another "Country" (any country in fact) the error message "An illegal choice has been detected. Please contact your site administrator." comes up.

I deleted the cache several times to no avail..

Comments

dave the brave’s picture

I am seeing the same issue, in my case we have 2 address fields on a single form, when one country is changed both update the state/province list BUT it seems like one or the other does not save within $form_state in the ajax call, so validation-time, its comparing an option to the incorrect list of options (in our case, US states because we default to that).

This is fairly easy to reproduce, just create 2 user address fields, and have them appear on the same form.

PS This is a fairly common scenario, e.g. a mailing and a physical/delivery address. We're also trying to copy over or hide the second address given a checkbox indicating both are the same.

damien tournoud’s picture

Status: Active » Closed (cannot reproduce)

I cannot reproduce with the latest iteration of the code, so I guess this is fixed.

jyee’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta1
Status: Closed (cannot reproduce) » Active

I'm seeing this error using beta1 with Drupal 7.4. Exactly the same as Damien's initial post.

dboulet’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev

Still seeing this problem with the latest 1.x-dev version. I also have 2 address fields on the same form.

dboulet’s picture

Unearthed a few clues.

Started off by modifying lines 1284 and 1285 of form.inc:

<?php
        elseif (!isset($options[$elements['#value']])) {
          dvm($options);
          dvm($elements['#value']);
          form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
?>

Now, changing the Country drop down output this:

  • array(
      'student' => 'Student',
      'pro' => 'Pro',
    )

  • FALSE

"Student" and "Pro" and options for radio buttons from another field which is required yet does not have a default value. If I choose an option for this field before changing the Country name in the address field, the error is gone. I suppose one workaround to this problem in my case would be to assign a default value for the radios.

Hope this helps.

jyee’s picture

@dboulet, thanks for the workaround tip. When I set a default on an unrelated field of radios in the same form as the addressfield, the error went away.

docwilmot’s picture

same error, and same solution works here. but not as easy for me: the other field on my form is a gender choice radios field. i cant exactly set a default gender! and it is required because, well, we all have a gender.

jyee’s picture

Why not set a default gender as long as users can change it? The other option (and the one that I used) is to have a third option of "decline to answer"... because, while we all have a gender, it may not always be as simple as male or female (e.g. drupal.org provides a "transgender" and "other" option), nor may users always want to provide that information.

docwilmot’s picture

good point jyee,
but i was mostly raising support for the issue at hand, which is that the module needs some work because of this. there might be some point where a form default cannot be set for someone's site.
thanks

davidwhthomas’s picture

Yes, this issue only appears to occur when there's a radio button element without a default value, on the same form.

pcambra’s picture

I can reproduce it as david says in #10. If you have a radio without default value in the same form, this error is displayed

robert.laszlo’s picture

Having the same issue.

13rac1’s picture

Status: Active » Closed (duplicate)

I've been dealing with this issue a lot recently. It is bug in core: #811542: Regression: Required radios throw illegal choice error when none selected

mobonobomo’s picture

Sorry to post in a closed issue, but changing the widget type for your required list field to 'select list' from checkboxes/radio buttons will remove the error, and you don't have to select a default value.