Drupal 7表格TextField自动完成不起作用



我是Drupal的新手,并且正在尝试使用包含自动完成功能的动态文本字段创建表单。此自动完成功能将从数据库中获取值。

我有以下代码:

表格:

function site_finder_form($form, &$form_state) {
    $form['site_finder_company_name'] = array(
        '#type' => 'textfield',        
         '#autocomplete_path' => 'companies/autocomplete',
    );
    /* Additional Form Fields here */
    return $form;
}

钩菜单:

function site_finder_menu()
{
    // path with autocomplete function for companies
    $items['companies/autocomplete'] = array(
        'page callback' => '_site_finder_autocomplete',
        'access arguments' => array('access companies autocomplete'),
        'type' => MENU_CALLBACK
    );
    return $items;
}

自动完成功能:

function _site_finder_autocomplete($string) {
    $matches = array();
    // Select Rows that match the query
    $companies =       db_select('company_info', 'e')
                     ->fields('e', array('Name'))
                     ->condition('Name', '%' . db_like($string) . '%', 'LIKE')
                     ->execute();
    // Query DB to get matches
    foreach ($companies as $company){
        $matches[$company->Name] = check_plain($company->Name);
    }
    drupal_json_output($matches);
}

我已经浏览了几个教程,以查看自动完成功能在Drupal中的工作原理,并且我遵循了挂钩菜单和自动完成功能的适当命名约定,所以我不确定为什么这不是当我在Textfield中输入值时工作。

任何帮助将非常感谢!

我意识到您必须清除Drupal缓存才能更改钩菜单才能生效。

相关内容

最新更新