You are here

function farm_area_import_form_create_validate in farmOS 7

Area importer form validation.

1 string reference to 'farm_area_import_form_create_validate'
farm_area_import_form in modules/farm/farm_area/farm_area_import/farm_area_import.module
Area import form.

File

modules/farm/farm_area/farm_area_import/farm_area_import.module, line 206
Farm area import module.

Code

function farm_area_import_form_create_validate(&$form, &$form_state) {

  // Iterate through the submitted values.
  foreach ($form_state['values']['output'] as $key => $values) {

    // If the confirmation checkbox is not checked, skip.
    if (empty($values['confirm'])) {
      continue;
    }

    // Prevent empty values.
    $fields = array(
      'name',
      'type',
      'geometry',
    );
    foreach ($fields as $field) {
      if (empty($values[$field])) {
        form_set_error('output][' . $key . '][' . $field, t('The %field field is required on geometry @num', array(
          '%field' => $field,
          '@num' => $key + 1,
        )));
      }
    }

    // Validate the geometry using the geofield function.
    $error = geofield_validate_geom(array(
      'geom' => $values['geometry'],
    ));
    if (!empty($error)) {
      form_set_error('output][' . $key . '][geometry', t('Geometry @num is invalid.', array(
        '@num' => $key + 1,
      )));
    }
  }
}