function geofield_latlon_element_validate in Geofield 7.2
Element validation function for geofield_latlon.
1 string reference to 'geofield_latlon_element_validate'
- geofield_element_info in ./
geofield.elements.inc - Implements hook_element_info().
File
- ./
geofield.elements.inc, line 115 - Provides FormAPI element callbacks for geofield_latlon and geofield_proximity.
Code
function geofield_latlon_element_validate($element, &$form_values) {
$components = array(
'lat' => array(
'title' => 'Latitude',
'range' => 90,
),
'lon' => array(
'title' => 'Longitude',
'range' => 180,
),
);
$allFilled = TRUE;
$anyFilled = FALSE;
foreach ($components as $key => $component) {
if (!empty($element[$key]['#value'])) {
if (!is_numeric($element[$key]['#value'])) {
form_error($element[$key], t('@title: @component_title is not numeric.', array(
'@title' => $element['#title'],
'@component_title' => $component['title'],
)));
}
elseif (abs($element[$key]['#value']) > $component['range']) {
form_error($element[$key], t('@title: @component_title is out of bounds.', array(
'@title' => $element['#title'],
'@component_title' => $component['title'],
)));
}
}
if ($element[$key]['#value'] == '') {
$allFilled = FALSE;
}
else {
$anyFilled = TRUE;
}
}
if ($anyFilled && !$allFilled) {
foreach ($components as $key => $component) {
if ($element[$key]['#value'] == '') {
form_error($element[$key], t('@title: @component_title must be filled too.', array(
'@title' => $element['#title'],
'@component_title' => $component['title'],
)));
}
}
}
}