You are here

function _quotes_autocomplete_author in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \_quotes_autocomplete_author()
  2. 6 quotes.module \_quotes_autocomplete_author()

Function to provide autocomplete for author field.

Parameters

string $string: The string currently entered by the user.

Return value

array An array of matches in JSON format.

1 string reference to '_quotes_autocomplete_author'
quotes_menu in ./quotes.module
Implements hook_menu().

File

./quotes.module, line 2387
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function _quotes_autocomplete_author($string) {
  $matches = array();
  $strlen = drupal_strlen($string);
  if ($strlen) {
    $result = db_query("SELECT name FROM {quotes_authors} WHERE LOWER(name) LIKE LOWER(:string)", array(
      ':string' => ($strlen > 1 ? '%%' : '') . addslashes($string) . '%%',
    ));
    foreach ($result as $row) {
      $matches[$row->name] = check_plain($row->name);
    }
  }
  drupal_json_output($matches);
}