Drupal为我们提供了表单的专用方法#ahah,所以只是将js里的ajax调用代码换了一种形式,更方便。
步骤:
一、表单中定义#ahah属性
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'SEARCH',
'#attributes' => array('class'=>'class-search'),
'#ahah' => array(
'event' => 'click',//定义触发事件类型
'method' => 'replace',//替换wrapper指向的容器里的内容,可以改成其它方式
'path' => 'class_search_results',//ahah调用的菜单路径
'wrapper' =>'content',//返回的内容将以method定义的方式来改变指定容器内容
'effect' => 'fade',//以渐现形式来显示返回的内容
'progress'=>array(
'type' => 'throbber',//会显示drupal默认的小时钟图标以表明是正在异步获取数据
),
),
);二、定义一个#ahah要调用的路径
$items['class_search_results'] = array(
'title' => t('Search Results'),
'page callback' => 'class_search_results',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);三、定义调用路径的回调函数
function class_search_results() {
$output = 'hello, ahah!';
drupal_json(array('status' => TRUE, 'data' => $output));
}- Admin's blog
- 347 reads
Comments
Post new comment