You are here

function countries_country_element_validate in Countries 7

Same name and namespace in other branches
  1. 8 countries.module \countries_country_element_validate()
  2. 7.2 countries.module \countries_country_element_validate()
2 string references to 'countries_country_element_validate'
countries_element_info in ./countries.module
Implement hook_element_info().
countries_field_widget_form in ./countries.module
Implements hook_field_widget_form().

File

./countries.module, line 161

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'],
    )));
  }
}