Ajax autocomplete Drupal
09.08.2015
Все это необходимо прописать в своем модуле.
-
Определяем элемент в форме, к которому будет прикручено автозаполнение
$form['item'] = array( '#type' => 'textfield', '#title' => t('Select the entry'), '#autocomplete_path' => 'nodes/autocomplete', );
-
Добавляем пункт меню для обработки url
$items['nodes/autocomplete'] = array( 'page callback' => 'nodes_autocomplete', 'access arguments' => user_access('access example autocomplete'), 'type' => MENU_CALLBACK, );
-
Определяем, чем будем заполнять
function nodes_autocomplete($string){ $items = array(); $result = db_query("SELECT nid, title FROM {node} WHERE status = 1 AND type='my_type' AND title LIKE LOWER ('%s%%')", $string) ; while($obj = db_fetch_object($result)) { $items[$obj->nid] = check_plain($obj->title); } drupal_json($items); }
