Autocompletamento in Drupal 6: come fare?

3 contenuti / 0 new
Ultimo contenuto
Autocompletamento in Drupal 6: come fare?

Ciao a tutti,
sto sviluppando un form dati e volevo sapere come funziona l'autocompletamento in Drupal 6. Ad esempio nel campo:

$form['title'] = array(
  '#type' => 'textfield',
  '#title' => t('Subject'),
  '#default_value' => $node->title,
  '#size' => 60,
  '#maxlength' => 128,
  '#required' => TRUE,
  '#autocomplete_path' => 'user/autocomplete',
);

cosa significa #autocomplete_path ? Posso creare una funzione che completa i campi da una mia tabella del database? Grazie per la dritta! Ciao

Grazie,
riporto il codice perchè questi post sono ben indicizzati sui motori. Ho utilizzato il codice così:

<?php
 
function elenchi_searchautocomplete_osp($string = '') {
 
$matches = array();
  if (
$string) {
   
$result = db_query_range("SELECT ospedale FROM {elenco_ospedali} WHERE LOWER(ospedale) LIKE LOWER('%%%s%%%%')", $string, 0, 12);
    while (
$row = db_fetch_object($result)) {
     
$matches[$row->ospedale] = check_plain($row->ospedale);
    }
  }
 
drupal_json($matches);
}
?>

Nell' hook_menu

<?php
  $items
['elenchi/searchautocomplete_osp'] = array(
   
'title' => t('Search autocomplete'),
   
'page callback' => 'elenchi_searchautocomplete_osp',
   
'access arguments' => array('view strutture elenchi'),
   
'type' => MENU_CALLBACK,
  );
 
?>

Nella funzione my_form

<?php
    $form
['info']['fieldsearch_ospedale'] = array(
     
'#type' => 'textfield',
     
'#title' => t('Inserisci Ospedale'),
     
'#maxlength' => 80,
     
'#size' => 60,
     
'#default_value' => $fieldsearch_ospedale,
     
'#required' => FALSE,
     
'#description' => t('Inserisci la parola da cercare per Ospedale se esiste in archivio allora appare'),
     
'#autocomplete_path' => 'elenchi/searchautocomplete_osp',
    );
 
?>

Grazie ancora ciao