hello,
i have created a module named : elisa_search
In my elisa_search.module, I have the functions below.

what happens ?
- If I do : http://mysite/?q=elisa_search/autocomplete/expo : it works, i have the node which title begin by "expo"
- in my page and my form, the field "recherche_serie" has a good autocomplete look, but autocomplete doesn't work at all.

Is there someone who can help me ?
I need to activate a module ? I need to put something in my elisa_search.info ?

thanks

// $Id: elisa_search.module,v 1.102 2009/07/03 23:35:49 quicksketch Exp $

//  hook_menu implementation

function elisa_search_menu() {
    $items["elisa_search/autocomplete"] = array(
        'title' => t('Recherche titres'),
        'page callback' => 'autocomplete',
        'access callback' => TRUE,
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK
    );
    return $items;
}

function autocomplete($value='') {

    $items = array();

    $result = db_query(db_rewrite_sql("SELECT title FROM {node} WHERE status = 1 AND type='article' AND title LIKE '%s%'"),check_plain($value));
    //$result = db_query(db_rewrite_sql("SELECT title FROM {node} WHERE status = 1 AND type='article' AND title LIKE '%s%'"),check_plain($value));

    while($obj = db_fetch_object($result)) {
        $_title = check_plain($obj->title);
        $items[$_title] = $_title;
    }

   print drupal_to_js($items);
   exit();
}

function elisa_search_form($form_state) {
    $form['recherche_serie'] = array(
        '#type' => 'textfield',
 //       '#title' => t('Recherche'),
        '#size' => 20,
        '#maxlength' => 30,
 //       '#description' => t('Texte'),
          '#autocomplete_path' => 'elisa_search/autocomplete',
 //       '#attributes' => array('class' => 'class-texte')
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('o'),
        '#attributes' => array('class' => 'class-btn')
        );

    $form['recherche_type'] = array(
                '#type' => 'radios',
//              '#title' => t('Type de recherche'),
//              '#description' => t('Select a type de recherche.'),
                '#options' => array(
                        'libre'=>t('Libre'),
                        'taxo'=>t('Mots clés'),
                        'titre'=>t('Titres')),
//              '#attributes' => array('class' => 'class-radio'),

                );

    $form['hidden'] = array('#type' => 'value', '#value' => 'serie_recherchee');
    return $form;
}

Comments

awlelo’s picture

I have found.
The code is good, but there were a problem with a CSS.
I have modified some css and autocomplete works fine now.

suramya’s picture

i am newbie in drupal..
i have implement same autosuggesion but not working .. :(
could u plz tell me how u fix it?