1 form.inc form_process_autocomplete($element)

Process function to prepare autocomplete data.

Parameters

$element: A textfield or other element with a #autocomplete_path.

Return value

array: The processed form element.

Related topics

File

core/includes/form.inc, line 4367
Functions for form and batch generation and processing.

Code

function form_process_autocomplete($element) {
  $element['#autocomplete_input'] = array();
  // Access to the autocomplete path is not checked here. The access callback
  // for the path is checked on each autocomplete request, along with the token
  // added below (see backdrop_valid_autocomplete_token()).
  if ($element['#autocomplete_path']) {
    $element['#autocomplete_input']['#id'] = $element['#id'] . '-autocomplete';
    // Force the script path to 'index.php', in case the server is not
    // configured to find it automatically. Normally it is the responsibility
    // of the site to do this themselves using hook_url_outbound_alter() (see
    // url()) but since this code is forcing non-clean URLs on sites that don't
    // normally use them, it is done here instead.
    $element['#autocomplete_input']['#url_value'] = url($element['#autocomplete_path'], array('absolute' => TRUE, 'clean' => FALSE, 'script' => 'index.php'));
    // Include a token that is sent with each autocomplete request, so that the
    // autocomplete callback may verify the request came from this form.
    $element['#autocomplete_input']['#token'] = backdrop_get_autocomplete_token($element['#autocomplete_path']);
  }
  return $element;
}