function countries_admin_form_validate in Countries 8
Same name and namespace in other branches
- 7.2 countries.admin.inc \countries_admin_form_validate()
- 7 countries.admin.inc \countries_admin_form_validate()
Validate country form submissions.
File
- ./
countries.admin.inc, line 207 - Admin page callbacks for the Countries module.
Code
function countries_admin_form_validate($form, &$form_state) {
$country = (object) $form_state['values'];
// Added to provide a better UI experience. Decide to keep or drop.
if (!empty($country->iso2) && ($existing = country_load($country->iso2))) {
// New country, the ISO alpha-2 must not be used.
if (empty($form['#country'])) {
form_set_error('iso2', t('Another country was found with this ISO alpha-2 code; !link', array(
'!link' => l(country_property($existing), 'admin/config/regional/countries/' . $existing->iso2),
)));
return;
}
elseif ($existing->iso2 != $form['#country']->iso2) {
form_set_error('iso2', t('Another country was found with this ISO alpha-2 code; !link', array(
'!link' => l(country_property($existing), 'admin/config/regional/countries/' . $existing->iso2),
)));
return;
}
}
if (country_validate($country)) {
$form_state['values'] = (array) $country;
}
else {
foreach ($country->_errors as $property => $error_message) {
form_set_error($property, $error_message);
}
}
}