You are here

function farm_movement_asset_location_validate in farmOS 7

Validation handler for processing the asset location field.

Parameters

array $form: The form array.

array $form_state: The form state array.

1 string reference to 'farm_movement_asset_location_validate'
farm_movement_form_farm_asset_form_alter in modules/farm/farm_movement/farm_movement.location.inc
Implements hook_form_FORM_ID_alter().

File

modules/farm/farm_movement/farm_movement.location.inc, line 130
Code for managing the location of assets with movement logs.

Code

function farm_movement_asset_location_validate(array $form, array &$form_state) {

  // Only proceed if current location field has a value.
  if (empty($form_state['values']['location']['areas'])) {
    return;
  }

  // Explode the value into an array and only take the first value.
  // (Same behavior as taxonomy autocomplete widget.)
  $values = drupal_explode_tags($form_state['values']['location']['areas']);

  // Iterate over the values.
  foreach ($values as $value) {

    // If the area name is over 255 characters long, throw a form validation
    // error.
    if (strlen($value) > 255) {
      $message = t('The area name "%name" is too long. It must be under 255 characters.', array(
        '%name' => $value,
      ));
      form_set_error('location][areas', $message);
    }
  }
}