【问题标题】:Drupal 7 Form Textfield Autocomplete Not WorkingDrupal 7表单文本字段自动完成不起作用
【发布时间】:2017-11-29 16:14:17
【问题描述】:

我是 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 中的工作原理,并且我遵循了挂钩菜单和自动完成功能的正确命名约定,所以我不太清楚为什么这不是当我在文本字段中输入值时工作。

非常感谢任何帮助!

【问题讨论】:

    标签: php sql drupal-7


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多