function field_reference_autocomplete_validate in Field reference 7
Validation callback for a field_reference autocomplete element.
1 string reference to 'field_reference_autocomplete_validate'
- field_reference_field_widget_form in ./
field_reference.module - Implements hook_field_widget_form().
File
- ./
field_reference.module, line 528 - Defines a field type for referencing a field from another.
Code
function field_reference_autocomplete_validate($element, &$form_state, $form) {
$field_key = NULL;
if (!empty($element['#value'])) {
// Check whether we have a field id.
preg_match('/.*?\\[(.*?)\\]/is', $element['#value'], $matches);
if (!empty($matches[1])) {
// Field id passed through.
$field_key = $matches[1];
}
else {
$instance = field_widget_instance($element, $form_state);
form_error($element, t('%name: field reference key not supplied in autocomplete value, please select an autocomplete suggestion.', array(
'%name' => $instance['label'],
)));
}
}
// Set the element's value as the field key.
form_set_value($element, $field_key, $form_state);
}