You are here

function google_map_field_latlon_validate in Google Map Field 7.2

Same name and namespace in other branches
  1. 7 google_map_field.module \google_map_field_latlon_validate()

Custom validation function for latitude/longitude fields.

1 string reference to 'google_map_field_latlon_validate'
google_map_field_field_widget_form in ./google_map_field.module
Implements hook_field_widget_form().

File

./google_map_field.module, line 364
This file defines all the necessary hooks and functions to create a Google Map Field field type for inserting maps directly into content items (node, entities etc).

Code

function google_map_field_latlon_validate($element, $form, &$form_state) {
  $invalid = FALSE;
  switch ($element['#parents'][count($element['#parents']) - 1]) {
    case 'lat':
      if ($element['#value'] < -90 || $element['#value'] > 90) {
        $invalid = TRUE;
      }
      break;
    case 'lon':
      if ($element['#value'] < -180 || $element['#value'] > 180) {
        $invalid = TRUE;
      }
      break;
  }
  if (!is_numeric($element['#value']) && !empty($element['#value']) || $invalid) {
    $field = implode('][', $element['#array_parents']);
    form_set_error($field, t('Invalid value - @title', array(
      '@title' => $element['#title'],
    )));
  }
}