ahah_example.module in Examples for Developers 6
Demo of some varieties of AHAH in Drupal 6. A tutorial based on this module is at http://randyfay.com/ahah.
File
ahah_example/ahah_example.moduleView source
<?php
/**
* @file
* Demo of some varieties of AHAH in Drupal 6.
* A tutorial based on this module is at http://randyfay.com/ahah.
*
*/
/**
* @defgroup ahah_example Example: AHAH
* @ingroup examples
* @{
* AHAH examples. (drupal 6)
*
* Provides simple examples of using AHAH with Drupal 6.
*
* - simplest_ahah: A tremendously simple example that just swaps out a div
* when you click the submit button (simplest_ahah)
*
* - autocheckboxes: Regenerate a form with the number of checkboxes
* determined by a select pulldown.
*
* - autotextfields: Regenerate a form with various textfields based on
* whether a checkbox is clicked.
*
* - dependent_dropdown: Change the value of dropdowns based on the
* value of other dropdowns.
*
* There is a tutorial based on this module at http://randyfay.com/ahah
*
* This example is part of the Examples for Developers Project which you can
* download and experiment with here: http://drupal.org/project/examples
*/
$path = drupal_get_path('module', 'ahah_example');
/**
* Implement hook_menu().
*
* Note that each item has both an entry point to prepare the form, and also
* a callback function that provides and AHAH menu callback.
*/
function ahah_example_menu() {
$items = array();
$items['examples/ahah_example'] = array(
'title' => 'AHAH Examples',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ahah_example_simplest',
),
'access callback' => TRUE,
'file' => 'ahah_example_simplest_ahah.inc',
);
// Simple AHAH with its callback.
$items['examples/ahah_example/simplest_ahah'] = array(
'title' => 'Simplest',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ahah_example_simplest',
),
'access callback' => TRUE,
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'ahah_example_simplest_ahah.inc',
'weight' => 0,
);
$items['examples/ahah_example/simplest_ahah/callback'] = array(
'page callback' => 'ahah_example_simplest_callback',
'access callback' => TRUE,
'file' => 'ahah_example_simplest_ahah.inc',
'type' => MENU_CALLBACK,
);
// Automatically generate checkboxes.
$items['examples/ahah_example/autocheckboxes'] = array(
'title' => 'Generate checkboxes',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ahah_example_autocheckboxes',
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'ahah_example_autocheckboxes.inc',
);
$items['examples/ahah_example/autocheckboxes/callback'] = array(
'page callback' => 'ahah_example_autocheckboxes_callback',
'access callback' => TRUE,
'file' => 'ahah_example_autocheckboxes.inc',
'type' => MENU_CALLBACK,
);
// Automatically generate textfields.
$items['examples/ahah_example/autotextfields'] = array(
'title' => 'Generate textfields',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ahah_example_autotextfields',
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
'weight' => 4,
'file' => 'ahah_example_autotextfields.inc',
);
$items['examples/ahah_example/autotextfields/callback'] = array(
'page callback' => 'ahah_example_autotextfields_callback',
'access callback' => TRUE,
'file' => 'ahah_example_autotextfields.inc',
'type' => MENU_CALLBACK,
);
// Automatically generate textfields.
$items['examples/ahah_example/dependent_dropdown'] = array(
'title' => 'Degrading dependent dropdown',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ahah_example_dropdown',
),
'access callback' => TRUE,
'weight' => 4,
'type' => MENU_LOCAL_TASK,
'file' => 'ahah_example_dependent_dropdown.inc',
);
$items['examples/ahah_example/dependent_dropdown/callback'] = array(
'page callback' => 'ahah_example_dropdown_callback',
'access callback' => TRUE,
'file' => 'ahah_example_dependent_dropdown.inc',
'type' => MENU_CALLBACK,
);
$items['examples/ahah_example/simple_validation'] = array(
'title' => 'Simple Validation',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ahah_example_simple_validation',
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
'file' => 'ahah_example_simple_validation.inc',
'weight' => 6,
);
$items['examples/ahah_example/simple_validation/callback'] = array(
'page callback' => 'ahah_example_simple_validation_callback',
'access callback' => TRUE,
'file' => 'ahah_example_simple_validation.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Does the very standard things that must be done in any normal callback.
* Used by each callback in this example module.
*/
function ahah_example_callback_helper() {
$form_state = array(
'storage' => NULL,
'submitted' => FALSE,
);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
// Enable the submit/validate handlers to determine whether AHAH-submittted.
$form_state['ahah_submission'] = TRUE;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
return $form;
}
/**
* Implements hook_init() to add module css.
*/
function ahah_example_init() {
drupal_add_css(drupal_get_path('module', 'ahah_example') . '/ahah_example.css');
}
/**
* @} End of "defgroup ahah_example".
*/
Functions
Name | Description |
---|---|
ahah_example_callback_helper | Does the very standard things that must be done in any normal callback. Used by each callback in this example module. |
ahah_example_init | Implements hook_init() to add module css. |
ahah_example_menu | Implement hook_menu(). |