You are here

function afb_autocomplete in Advanced Form Block 7

Autocomplete function displaying each node names.

1 string reference to 'afb_autocomplete'
afb_menu in ./afb.module
Implements hook_menu().

File

./afb.module, line 244
Allows administrators to create blockd of node add/edit forms.

Code

function afb_autocomplete($string) {
  $matches = array();
  $result = db_select('node', 'n')
    ->fields('n', array(
    'title',
    'nid',
  ))
    ->condition('title', '%' . db_like($string) . '%', 'LIKE')
    ->addTag('node_access')
    ->execute();

  // Save the query to matches.
  foreach ($result as $row) {
    $matches[$row->nid] = check_plain($row->title);
  }

  // Return the result to the form in json.
  drupal_json_output($matches);
}