function _webform_civicrm_form_validate in Webform CiviCRM Integration 7.2
Same name and namespace in other branches
- 6.2 webform_civicrm_forms.inc \_webform_civicrm_form_validate()
Recursive validation callback for webform submissions.
1 call to _webform_civicrm_form_validate()
- webform_civicrm_form_validate in ./
webform_civicrm.module - Validation callback for webform submissions.
File
- ./
webform_civicrm_forms.inc, line 1080
Code
function _webform_civicrm_form_validate($form, &$form_state, $submitted) {
// Recurse through form elements.
foreach (element_children($form) as $key) {
if (is_array($form[$key]) && ($element = $form[$key])) {
_webform_civicrm_form_validate($form[$key], $form_state, $submitted);
if (!empty($element['#civicrm_data_type']) && substr(webform_civicrm_aval($element, '#type', ''), 0, 4) === 'text' && $element['#value'] !== NULL && $element['#value'] !== '') {
$dt = $element['#civicrm_data_type'];
// Validate state/prov abbreviation
if ($dt == 'state_province_abbr') {
$ckey = str_replace('state_province', 'country', $key);
if (!empty($submitted[$ckey]) && is_numeric($submitted[$ckey])) {
$country_id = $submitted[$ckey];
}
else {
$config = CRM_Core_Config::singleton();
$country_id = $config->defaultContactCountry;
}
$states = webform_civicrm_get_options('state_province', $country_id);
if ($states && !array_key_exists(strtoupper($element['#value']), $states)) {
$countries = webform_civicrm_get_options('country');
form_error($element, t('Mismatch: "@state" is not a state/province of %country. Please enter a valid state/province abbreviation for %field.', array(
'@state' => $element['#value'],
'%country' => $countries[$country_id],
'%field' => $element['#title'],
)));
}
}
elseif ($dt !== 'String' && $dt !== 'Memo' && $dt !== 'File' && CRM_Utils_Type::escape($element['#value'], $dt, FALSE) === NULL) {
// Allow data type names to be translated
switch ($dt) {
case 'Int':
$dt = t('an integer');
break;
case 'Float':
$dt = t('a number');
break;
case 'Link':
$dt = t('a web address starting with http://');
break;
case 'Money':
$dt = t('a currency value');
break;
}
form_error($element, t('Please enter @type for %field.', array(
'@type' => $dt,
'%field' => $element['#title'],
)));
}
}
}
}
}