You are here

function geolocation_field_validate in Geolocation Field 7

Implements hook_field_validate().

File

./geolocation.module, line 103
A geolocation field using the Field API.

Code

function geolocation_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (!geolocation_field_is_empty($item, $field)) {
      switch (TRUE) {
        case !is_numeric($item['lat']):
          $errors[$field['field_name']][$langcode][$delta][] = array(
            'error' => 'geolocation_invalid_lat',
            'message' => t('Invalid Latitude. Value must be numeric.'),
          );
          break;
        case $item['lat'] > 90:
        case $item['lat'] < -90:
          $errors[$field['field_name']][$langcode][$delta][] = array(
            'error' => 'geolocation_invalid_lat',
            'message' => t('Invalid Latitude. Value must be between 90 and -90.'),
          );
          break;
      }
      switch (TRUE) {
        case !is_numeric($item['lng']):
          $errors[$field['field_name']][$langcode][$delta][] = array(
            'error' => 'geolocation_invalid_lng',
            'message' => t('Invalid Longitude. Value must be numeric.'),
          );
        case $item['lng'] > 180:
        case $item['lng'] < -180:
          $errors[$field['field_name']][$langcode][$delta][] = array(
            'error' => 'geolocation_invalid_lng',
            'message' => t('Invalid Longitude. Value must be between 180 and -180'),
          );
          break;
      }
    }
  }
}