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
Comment #1
socialnicheguru commentedWill 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.
Comment #2
yesct commentedThis 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.
Comment #3
summit commentedSubscribing, greetings, Martijn
Comment #4
aaronbaumanYou 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.
Comment #5
aaronbaumanAlso, 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.
Comment #6
mos2710 commentedHi,
Would you be able to do the same for the phone (and possibly fax) validation?
Thanks
Mos2710
Comment #7
arski commentedHm, 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 :(
Comment #8
marcvangendAlmost 2 years later, but thanks! The patch in #5 worked for me to enable province validation when the country was set to "force default".
Comment #9
podarokpostponed before tests fix
#1931088: [META] Fixing tests
Comment #10
podaroktests fixed #1931088: [META] Fixing tests
lets go
Comment #12
jerdiggity commentedLooks like some of this issue was already committed (the first part, regarding line 126) but regardless, submitting patch for the remainder of the list.
Comment #13
podarok#12 commited pushed to 7.x-3.x and 6.x-3.x
thanks!!
Comment #14
jerdiggity commentedNo prob. :)
Comment #15
podarokhttp://drupal.org/node/1942736 tagged in alpha release