Skip to content

Commit

Permalink
Only perform validation on county/state field when it is set (coleman…
Browse files Browse the repository at this point in the history
  • Loading branch information
JKingsnorth committed Jul 17, 2021
1 parent 26566d8 commit 28ae8fc
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions includes/wf_crm_webform_postprocess.inc
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,19 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
$dt = $element['#civicrm_data_type'];
// Validate state/prov abbreviation
if ($dt == 'state_province_abbr') {
$ckey = str_replace('state_province', 'country', $key);
if (!empty($this->crmValues[$ckey]) && is_numeric($this->crmValues[$ckey])) {
$country_id = $this->crmValues[$ckey];
}
else {
$country_id = wf_crm_get_civi_setting('defaultContactCountry', 1228);
}
$states = wf_crm_get_states($country_id);
if ($states && !array_key_exists(strtoupper($element['#value']), $states)) {
$countries = wf_crm_apivalues('address', 'getoptions', ['field' => 'country_id']);
form_error($element, t('Mismatch: "@state" is not a state/province of %country. Please enter a valid state/province abbreviation for %field.', ['@state' => $element['#value'], '%country' => $countries[$country_id], '%field' => $element['#title']]));
if (!empty($this->crmValues[$key])) {
$ckey = str_replace('state_province', 'country', $key);
if (!empty($this->crmValues[$ckey]) && is_numeric($this->crmValues[$ckey])) {
$country_id = $this->crmValues[$ckey];
}
else {
$country_id = wf_crm_get_civi_setting('defaultContactCountry', 1228);
}
$states = wf_crm_get_states($country_id);
if ($states && !array_key_exists(strtoupper($element['#value']), $states)) {
$countries = wf_crm_apivalues('address', 'getoptions', ['field' => 'country_id']);
form_error($element, t('Mismatch: "@state" is not a state/province of %country. Please enter a valid state/province abbreviation for %field.', ['@state' => $element['#value'], '%country' => $countries[$country_id], '%field' => $element['#title']]));
}
}
}
// Strings and files don't need any validation
Expand Down

0 comments on commit 28ae8fc

Please sign in to comment.