You are here

drupal #ahah属性(3)

老葛的Drupal培训班 Think in Drupal

下面是一个表单的简单示例,它允许使用AHAH来动态替换一些文本。按钮使用throbber来指示用户应该继续等待,如图10-18所示。这里是sites/all/modules/custom/poof/poof.info:
 
; $Id$
name = Poof
description = Demonstrates AHAH forms.
package = Pro Drupal Development
core = 6.x
 
    而下面则是sites/all/modules/custom/poof/poof.module:
 
<?php
 
/**
 * Implementation of hook_menu().
 */
function poof_menu() {
    $items['poof'] = array(
        'title' => 'Ahah!',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('poof_form'),
        'access arguments' => array('access content'),
    );
    $items['poof/message_js'] = array(
        'page callback' => 'poof_message_js',
        'type' => MENU_CALLBACK,
        'access arguments' => array('access content'),
    );
    return $items;
}
 
/**
 * Form definition.
 */
function poof_form() {
    $form['target'] = array(
        '#type' => 'markup',
        '#prefix' => '<div id="target">',
        '#value' => t('Click the button below. I dare you.'),
        '#suffix' => '</div>',
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Click Me'),
        '#ahah' => array(
            'event' => 'click',
            'path' => 'poof/message_js',
            'wrapper' => 'target',
            'effect' => 'fade',
        )
    );
 
    return $form;
}
 
/**
 * Menu callback for AHAH additions.
 */
function poof_message_js() {
    $output = t('POOF!');
    drupal_json(array('status' => TRUE, 'data' => $output));
}
 
10-18.点击按钮后,将会显示一个圆形的转动的throbber图标,之后将会进行基于AHAH的文本替换。
 

Drupal版本: