function _countries_country_element_validate in Countries 8
Same name and namespace in other branches
- 7.2 countries.elements.inc \_countries_country_element_validate()
Validate callback for the country FAPI element.
1 call to _countries_country_element_validate()
- countries_country_element_validate in ./
countries.module - Validate callback for the country FAPI element.
File
- ./
countries.elements.inc, line 68 - Defines all element related code for the countries module.
Code
function _countries_country_element_validate($element, &$form_state) {
if (!isset($element['#cardinality'])) {
return;
}
$values = array();
if (!is_array($element['#value'])) {
$element['#value'] = array_filter(array(
$element['#value'],
));
}
foreach (array_values($element['#value']) as $value) {
$values[] = array(
'iso2' => $value,
);
}
if ($element['#cardinality'] >= 0 && count($values) > $element['#cardinality']) {
$title = empty($element['#title']) ? t('Countries') : $element['#title'];
form_error($element, t('%name field is restricted to %max countries.', array(
'%name' => $title,
'%max' => $element['#cardinality'],
)));
}
}