复制代码代码如下: <?PHP function module_name_fORM() { $form = array(); $form['city'] = array( '#title' => t('Cit
复制代码代码如下:
<?PHP
$form = array();
$form['city'] = array(
'#title' => t('City'),
'#type' => 'textfield',
'#autocomplete_path' => 'example/autocomplete',//--调用的路径
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
return $form;
}
//--定义路径
function module_name_menu() {
$items['example/autocomplete'] = array(
'page callback' => '_module_name_autocomplete', //--调用数据
'access arguments' => array('access example autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
//--从数据库读取返回数据
function _module_name_autocomplete($string) {
$matches = array();
// Some fantasy DB table which holds cities
$query = db_select('cities', 'c');
// Select rows that match the string
$return = $query
->fields('c', array('city'))
->condition('c.city', '%' . db_like($string) . '%', 'LIKE')
->range(0, 10)
->execute();
// add matches to $matches
foreach ($return as $row) {
$matches[$row->city] = check_plain($row->city);
}
// return for js
drupal_JSON_output($matches); //--json格式返回
}
?>
--结束END--
本文标题: drupal 自定义表单调用autocomplete主标签实现代码
本文链接: https://lsjlt.com/news/32666.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-27
2023-10-27
2023-10-26
2023-10-25
2023-10-21
2023-10-21
2023-10-18
2023-10-12
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0