You are here

function _apachesolr_reference_autocomplete_validate in Apachesolr Reference 7

Validates the value of an autocomplete field.

Parameters

array $element: the element field object

array $form_state: the form state array

array $form: the form array

1 string reference to '_apachesolr_reference_autocomplete_validate'
apachesolr_reference_field_widget_form in ./apachesolr_reference.module
Implements hook_field_widget_form().

File

./apachesolr_reference.module, line 487
functionality for creating reference fields to apache solr objects.

Code

function _apachesolr_reference_autocomplete_validate($element, &$form_state, $form) {

  // If a value was entered into the autocomplete...
  $value = '';

  // And the value is not empty.
  if (!empty($element['#value'])) {

    // Take "label (id)', match the id from parenthesis.
    if (preg_match("/.+\\(([^)]+)\\)/", $element['#value'], $matches)) {
      $value = $matches[1];
    }
  }

  // Update the value of this element so the field can validate the product IDs.
  form_set_value($element, $value, $form_state);
}