The location fieldset is not really validated at all (at least in my machine, drupal 6). I made it work by making the following changes:

Change line 126 of location.module from:

'#validate' => array('location_element_validate' => array()),

to

'#element_validate' => array('location_element_validate'),

also change the following block (starting at line 558) (adding the ['#value'], etc.):

    case 'validate':
     if (!empty($obj['country'])) {
        if (!empty($obj['province']) && !empty($obj['province']['#value'])) {
          $provinces = location_get_provinces($obj['country']['#value']);	
          $found = FALSE;
          $p = strtoupper($obj['province']['#value']);
          foreach ($provinces as $k => $v) {
            if ($p == strtoupper($k) || $p == strtoupper($v)) {
              $found = TRUE;
              break;
            }
          }
          if (!$found) {
            form_error($obj['province'], t('The specified province was not found in the specified country.'));
          }
        }
      }

and (line 1550)

function location_element_validate($element, &$form_state) {
  location_invoke_locationapi($element, 'validate'); 
}

Comments

socialnicheguru’s picture

Status: Active » Needs review

Will this work on D5? I will see if the same issue is there (with location I am finding that if something is broken on D6 it is usually broken on D5 too).

Changing this to patch code needs review. It isn't in the proper format, but maybe someone who knows more than I can help out so we can make sure this gets into location module.

Thanks again.

yesct’s picture

Status: Needs review » Needs work
Issue tags: +location validation

This will get more people reviewing, and maybe committed easier if it is a patch. Check out: http://drupal.org/patch/create and make sure you create the patch against the current dev version. Maybe post a patch against both the D6 and D5 branch.

Also tagging.

summit’s picture

Subscribing, greetings, Martijn

aaronbauman’s picture

You can't just add ['#value'] in locationapi so that it will work with FAPI.
I presume this will break all other implementations of locationapi where it is used.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.85 KB

Also, the fix above doesn't address the case when "Force default" is enabled for country.

I'm pretty sure this issue is a duplicate, but it's the first one that came up when I searched.

Here's a patch that works for me.

mos2710’s picture

Hi,

Would you be able to do the same for the phone (and possibly fax) validation?

Thanks
Mos2710

arski’s picture

Hm, what happens if I don't have the province data for a specific country, but still want to allow the users to enter some values, without validation? At the moment I just get the message that the province is incorrect for the given country :(

marcvangend’s picture

Version: 6.x-3.0 » 6.x-3.1
Status: Needs review » Reviewed & tested by the community

Almost 2 years later, but thanks! The patch in #5 worked for me to enable province validation when the country was set to "force default".

podarok’s picture

Status: Reviewed & tested by the community » Postponed

postponed before tests fix
#1931088: [META] Fixing tests

podarok’s picture

Version: 6.x-3.1 » 6.x-3.x-dev
Status: Postponed » Needs review

tests fixed #1931088: [META] Fixing tests
lets go

Status: Needs review » Needs work

The last submitted patch, province-validation.patch, failed testing.

jerdiggity’s picture

Status: Needs work » Needs review
StatusFileSize
new1.67 KB

Looks like some of this issue was already committed (the first part, regarding line 126) but regardless, submitting patch for the remainder of the list.

podarok’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Fixed

#12 commited pushed to 7.x-3.x and 6.x-3.x
thanks!!

jerdiggity’s picture

No prob. :)

podarok’s picture

http://drupal.org/node/1942736 tagged in alpha release

Status: Fixed » Closed (fixed)
Issue tags: -location validation

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