I am having an issue on a site of mine that when a user registers, it is setup to make them enter an address. There are certain countries that don't return any state/provinces and it shows "Non-Applicable", but when the form is submitted, it gives an "State/Province field is required." error and there is no way for the user to proceed. You can test this issue by going to http://www.openhisword.com/user/register and select for instance, "TANZANIA, UNITED REPUBLIC OF" from the drop down. Any ideas?

Thanks!

CommentFileSizeAuthor
#16 uc_addresses_address_pane.inc_.patch1.49 KBBao Ha

Comments

freixas’s picture

This should work the same was as for the checkout billing and delivery addresses. Do you only have the problem with when registering (and not on checkout)?

openhisword’s picture

I am the guy aj built the site for. We've got it setup so users must login or create an account before they can go to check out. So we would like to be able to have state/province not required for the countries that don't have them. We get a lot of international customers. Thanks for you help!!

freixas’s picture

I'm sorry but I still need an answer to my question: does this problem only occur during registration or does it also occur during checkout?

openhisword’s picture

Yeah, no problems if an unregistered user checks out. Same n/a in the state field, but it lets you complete the check-out.

freixas’s picture

Thanks for the response. I was hoping for a different answer so I could send you over to the Ubercart people :-)

Continued maintenance of this module is not my highest priority. If you need a fix for this anytime soon, you're probably going to have to find the problem (and solution) yourself. If you're not a programmer, you can hire me (which increases the priority dramatically) or hire someone else and have them fix the bug and submit a patch (so the fix gets included in future updates).

If this is not critical, you could wait until I get around to looking at this.

ajrock2000’s picture

I am a programmer myself, but I have no experience with drupal. Can you give me any hints as to where the validation logic is located?

freixas’s picture

Of course. It's not super-hard, although you may wind up tracing through Ubercart code.

I assume you know where the modules are located. If not, look for folders called "uc_addresses" and "ubercart".

Start with uc_addresses. There are only two files to worry about: uc_addresses.module and uc_addresses_address_pane.inc. The latter may do the validation or it may pass it off to uc_addresses.module. I included a lot of comments, so it shouldn't be too hard to find.

The next step should be to look into ubercart. It's divided into sub-modules. Since the checkout code works, it might be nice to compare it to the code I use. The uc_addresses code started as a clone of uc_order and maybe parts of uc_cart (someone else started writing uc_addresses and I took it over), so check there.

When you run into a function call and you don't know what it is, use Google and type in the name. This usually leads you to the documentation.

Good luck! If you fix the problem, please send in a patch so your fix doesn't get wiped out by future releases of uc_addresses.

coloryan’s picture

Was this every resolved? I'm having the same issue with Denmark and a few other countries.

freixas’s picture

No, it has not been resolved. Would you like to fix it?

coloryan’s picture

Would I, yes... do I have the ability... unfortunately, no. After the holidays I can ask someone to look at it though, but no promises on delivery/ability.

drewmacphee’s picture

I'm getting something similar during registration.

I have just Canada and the US for countries and when I pick Canada and submit it give me

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

and highlights the state/province box.. when I go to make a selection it now shows US states instead of Canadian Provinces.

But only during registration.. if you create one after it works fine.

freixas’s picture

Sounds like you are actually reporting the bug in #376632: Returning "An illegal choice has been detected. Please contact the site administrator" when changing country. Have you tried 6.x-1.0-rc1?

coloryan’s picture

I'm running 6.x-1.0-rc1 and am getting that error.

When I request Denmark, the response on submit is: 'State/Province field is required.'

drewmacphee’s picture

Same.. on rc1

freixas’s picture

Assigned: ajrock2000 » freixas

OK, I had a little bit of time to look at this.

I imported Tanzania and Denmark into my site. I couldn't duplicate the problem with Tanzania—on my site, Tanzania has different zones available. I must have got the wrong Tanzania. In any case, using Denmark allowed me to reproduce the problem.

I could not reproduce this problem with Canada. The problem drewmacphee reported is different from the original bug report and matches the symptoms in #376632: Returning "An illegal choice has been detected. Please contact the site administrator" when changing country. This bug is the "State/Province field required" error, not the "An illegal choice has been detected" error.

The checkout form doesn't have this problem. However, my Add/Edit Addresses forms have the problem, so it's not just registration.

The zone mechanism has caused me a lot of grief. It uses Drupal's AHAH code and there's some magic that needs to happen to keep Drupal's form structure synchronized with the changes that the Javascript makes to the form.

The problem is that the Zone value is required. If a country is selected without zones, then the Javascript code changes the field to "Non-Applicable" and makes the field unselectable. The Drupal form, however, still thinks the field is required. It's the Drupal form mechanism that checks for and reports the error, so by the time my code gets called it's too late (in fact, I don't think I get called if there's an error).

So I understand the basic problem, but it would take a bit of time to find out the right way to solve it. I welcome contributions.

A poor workaround is to change the zone field so it is not required. Unfortunately, this creates a problem for countries with zones.

Bao Ha’s picture

Version: 6.x-1.x-dev » 6.x-1.0-rc1
StatusFileSize
new1.49 KB

While waiting for the resolution of this problem, I temproraily patch the uc_addresses_address_pane.inc file, see the attchment, as a work-around.

dannypfeiffer’s picture

Correct me if I'm wrong, but that patch appears to just make the state/province field always 'not required'... same as making state/province not required in the Ubercart Checkout Settings.

Instead, you can conditionally make state/province not required upon posting by adding this bit of code right after line 82 (right after you set the zone's value):
( oops.. this also needs to be added in the 'edit' section )

if (isset($_POST['panes']) && count($form['address']['zone']['#options']) == 1) {
   $form['address']['zone']['#required'] = FALSE;
 }

This is a slight adaptation of the official fix of this problem in the ubercart module checkout panes.
http://www.ubercart.org/forum/support/2462/statezone_field_required_when...

freixas’s picture

@dpfiffe: To be honest, I never got around to looking at the patch. Thanks for checking it out and suggesting a better alternative. I really need to get this fix in the code.

freixas’s picture

Status: Active » Fixed

Thanks to dpfiffe, this bug is now fixed. The fix is checked in and should appear in any dev build dated on or after 7/10/2010.

@dpfiffe: I had to remove the isset[$_POST['panes'] test to make this fix the problem during registration, as well as during add/edit. The test does not appear to be necessary.

Status: Fixed » Closed (fixed)

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