I get this during 5.x-2.0-rc1 and 5.x-1.x-dev...

When creating a new address with any country outside of the US, the zones load but when I select one and submit, it reverts to the US zones and says..

"An illegal choice has been detected. Please contact the site administrator."

This happens during registration, during "add an address" and during checkout (selecting an address).

Any help would be appreciated!

Comments

ckenda1’s picture

Wanted to add some info..

This doesn't happen if I remove/uninstall uc_addresses. Users then have to enter all their info at checkout, but it works fine. With uc_addresses installed and in use, any non-US country that gets selected, the correct zones populate, but then when you select a zone and submit I get the error above and the Zones revert to US zones even though the Country is still correct.

Again, this happens during registration, during "add an address" and during checkout (selecting an address).

thanks

ckenda1’s picture

Watchdog log as promised...

Type form
Date Saturday, September 13, 2008 - 01:11
User admin
Location ..removed..
Referrer ..removed..
Message Illegal choice 1798 in Zone element.
Severity error
Hostname ..removed..

I get different "Illegal choice" messages, but all related to the bug above..

freixas’s picture

Assigned: Unassigned » freixas

I was able to duplicate.

freixas’s picture

Status: Active » Fixed

Ok, I think this is now fixed. I started with some code copied from uc_order. The fix was to revise how I check for the country code,

For uc_order, the code is:

      if (uc_address_field_enabled('zone')) {
        if (isset($_POST['delivery_country'])) {
          $country_id = intval($_POST['delivery_country']);
        }
        else {
          $country_id = $arg1->delivery_country;
        }

This is similar to what I was using. My new code is:

      if (uc_address_field_enabled('zone')) {
	if (isset($_POST['panes'], $_POST['panes']['address'], $_POST['panes']['address']['country'])) {
	  $country_id = intval($_POST['panes']['address']['country']);
	}
	else {
	  $country_id = $arg1->country;
	}

The country value was stored in a difference place in the $POST array. This fix was made in two places in uc_addresses_address_pane.inc.

In the process of testing this, I found and fixed a bug with the new address name feature, so this is a twofer.

I just checked the code into CVS and it should appear in the dev build tomorrow or so.

Thanks for reporting this problem. Please let me know if this resolves your issue.

ckenda1’s picture

When you say dev build, do you mean 2.0-rcx or 1.x-dev ?

I'll try it out tomorrow and let you know if this fixed it.

Thanks!

ckenda1’s picture

Doesn't occur when adding a new address, but the bug is still there during account registration.

freixas’s picture

Figures. The form is the same for registration as for adding a new address, so I figured I didn't need to check. As it happens, I need the old code for registration and the new code for adding/editing an address (in My Account).

The revised code is now checked in and this time, I tried registering a new account with a Canadian address, adding a Canadian address, editing a US address into Canadian and vice versa, placing an order with a Canadian address (logged in) and placing an order with a Canadian address (logged out).

All of these worked for me as expected.

We still have a few mysteries:

  • To make this work for new user registrations, I had to restore the $_POST check back to its old form. So I have no idea why you ever had trouble with registration. If it was broken for you earlier, I have just restored it to its broken state.
  • None of the changes I have made affect the checkout forms. If they were broken for you before, they should still be broken now.

However, if this fixes your problems, we can bow to the programming Gods and get on with other work. Let me know.

ckenda1’s picture

Status: Fixed » Active

Nope, registration is still broken. Adding an address and checkout do work though.

Bug sounds somewhat similar to this one...
http://drupal.org/node/285501

freixas’s picture

Well, that link that was a real trip through the past...

So there was a problem previously and someone debugged it and decided that changing the reference to the $_POST variable would fix it. And now, to fix a similar problem, I changed it back. Lovely.

It's clear that for the country code to work, I need to get the posted country value. It's also clear that the location of this value varies from form to form.

It's all working for me right now as far as I can tell, so we have a couple of options:

  • Walk me through the exact steps you use to reproduce the error. Let me know any relevant setup.
  • If you are a programmer, you can poke in uc_addresses_address_pane.inc and see what's happening. The simplest way: Look for the references to $_POST and place a var_dump($_POST) right before there. See what the $_POST array contains when you get the error. We're looking for where the country value is stored.

Thanks for your help.

freixas’s picture

Status: Active » Fixed

Finally fixed (I hope)! Checked into CVS.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.