国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

drupal 自定義表單調用autocomplete主標簽實現代碼

2024-08-30 19:07:47
字體:
來源:轉載
供稿:網友


<?php
function module_name_form() {
$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格式返回
}
?>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 齐齐哈尔市| 拜泉县| 砀山县| 梅州市| 桃源县| 故城县| 横山县| 海南省| 田阳县| 三明市| 昭通市| 灵宝市| 平南县| 台前县| 唐海县| 涟源市| 迁西县| 襄汾县| 乐业县| 特克斯县| 顺昌县| 红安县| 金湖县| 普宁市| 遵义市| 盐池县| 阿克陶县| 峨山| 化隆| 循化| 云林县| 福海县| 普定县| 潮安县| 马尔康县| 乌鲁木齐市| 将乐县| 吕梁市| 竹山县| 夹江县| 辰溪县|