ahah_example.module

  1. examples
    1. 6 ahah_example/ahah_example.module

Demo of some varieties of AHAH in Drupal 6. A tutorial based on this module is at http://randyfay.com/ahah.

Functions & methods

NameDescription
ahah_example_callback_helperDoes the very standard things that must be done in any normal callback. Used by each callback in this example module.
ahah_example_initImplements hook_init() to add module css.
ahah_example_menuImplement hook_menu().

File

ahah_example/ahah_example.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Demo of some varieties of AHAH in Drupal 6.
  5. * A tutorial based on this module is at http://randyfay.com/ahah.
  6. *
  7. */
  8. /**
  9. * @defgroup ahah_example Example: AHAH
  10. * @ingroup examples
  11. * @{
  12. * AHAH examples. (drupal 6)
  13. *
  14. * This example is part of the Examples for Developers Project which you can download
  15. * and experiment with here: http://drupal.org/project/examples
  16. */
  17. $path = drupal_get_path('module','ahah_example');
  18. /**
  19. * Implement hook_menu().
  20. *
  21. * Note that each item has both an entry point to prepare the form, and also
  22. * a callback function that provides and AHAH menu callback.
  23. */
  24. function ahah_example_menu() {
  25. $items = array();
  26. $items['examples/ahah_example'] = array(
  27. 'title' => 'AHAH Examples',
  28. 'page callback' => 'drupal_get_form',
  29. 'page arguments' => array('ahah_example_simplest'),
  30. 'access callback' => TRUE,
  31. 'file' => 'simplest_ahah.inc',
  32. );
  33. // Simple AHAH with its callback.
  34. $items['examples/ahah_example/simplest_ahah'] = array(
  35. 'title' => 'Simplest',
  36. 'page callback' => 'drupal_get_form',
  37. 'page arguments' => array('ahah_example_simplest'),
  38. 'access callback' => TRUE,
  39. 'type' => MENU_DEFAULT_LOCAL_TASK,
  40. 'file' => 'simplest_ahah.inc',
  41. 'weight' => 0,
  42. );
  43. $items['examples/ahah_example/simplest_ahah/callback'] = array(
  44. 'page callback' => 'ahah_example_simplest_callback',
  45. 'access callback' => TRUE,
  46. 'file' => 'simplest_ahah.inc',
  47. 'type' => MENU_CALLBACK,
  48. );
  49. // Automatically generate checkboxes.
  50. $items['examples/ahah_example/autocheckboxes'] = array(
  51. 'title' => 'Generate checkboxes',
  52. 'page callback' => 'drupal_get_form',
  53. 'page arguments' => array('ahah_example_autocheckboxes'),
  54. 'access callback' => TRUE,
  55. 'type' => MENU_LOCAL_TASK,
  56. 'weight' => 2,
  57. 'file' => 'autocheckboxes.inc',
  58. );
  59. $items['examples/ahah_example/autocheckboxes/callback'] = array(
  60. 'page callback' => 'ahah_example_autocheckboxes_callback',
  61. 'access callback' => TRUE,
  62. 'file' => 'autocheckboxes.inc',
  63. 'type' => MENU_CALLBACK,
  64. );
  65. // Automatically generate textfields.
  66. $items['examples/ahah_example/autotextfields'] = array(
  67. 'title' => 'Generate textfields',
  68. 'page callback' => 'drupal_get_form',
  69. 'page arguments' => array('ahah_example_autotextfields'),
  70. 'access callback' => TRUE,
  71. 'type' => MENU_LOCAL_TASK,
  72. 'weight' => 4,
  73. 'file' => 'autotextfields.inc',
  74. );
  75. $items['examples/ahah_example/autotextfields/callback'] = array(
  76. 'page callback' => 'ahah_example_autotextfields_callback',
  77. 'access callback' => TRUE,
  78. 'file' => 'autotextfields.inc',
  79. 'type' => MENU_CALLBACK,
  80. );
  81. // Automatically generate textfields.
  82. $items['examples/ahah_example/dependent_dropdown'] = array(
  83. 'title' => 'Degrading dependent dropdown',
  84. 'page callback' => 'drupal_get_form',
  85. 'page arguments' => array('ahah_example_dropdown'),
  86. 'access callback' => TRUE,
  87. 'weight' => 4,
  88. 'type' => MENU_LOCAL_TASK,
  89. 'file' => 'dependent_dropdown.inc',
  90. );
  91. $items['examples/ahah_example/dependent_dropdown/callback'] = array(
  92. 'page callback' => 'ahah_example_dropdown_callback',
  93. 'access callback' => TRUE,
  94. 'file' => 'dependent_dropdown.inc',
  95. 'type' => MENU_CALLBACK,
  96. );
  97. $items['examples/ahah_example/simple_validation'] = array(
  98. 'title' => 'Simple Validation',
  99. 'page callback' => 'drupal_get_form',
  100. 'page arguments' => array('ahah_example_simple_validation'),
  101. 'access callback' => TRUE,
  102. 'type' => MENU_LOCAL_TASK,
  103. 'file' => 'ahah_example_simple_validation.inc',
  104. 'weight' => 6,
  105. );
  106. $items['examples/ahah_example/simple_validation/callback'] = array(
  107. 'page callback' => 'ahah_example_simple_validation_callback',
  108. 'access callback' => TRUE,
  109. 'file' => 'ahah_example_simple_validation.inc',
  110. 'type' => MENU_CALLBACK,
  111. );
  112. return $items;
  113. }
  114. /**
  115. * Does the very standard things that must be done in any normal callback.
  116. * Used by each callback in this example module.
  117. */
  118. function ahah_example_callback_helper() {
  119. $form_state = array('storage' => NULL, 'submitted' => FALSE);
  120. $form_build_id = $_POST['form_build_id'];
  121. $form = form_get_cache($form_build_id, $form_state);
  122. $args = $form['#parameters'];
  123. $form_id = array_shift($args);
  124. $form_state['post'] = $form['#post'] = $_POST;
  125. // Enable the submit/validate handlers to determine whether AHAH-submittted.
  126. $form_state['ahah_submission'] = TRUE;
  127. $form['#programmed'] = $form['#redirect'] = FALSE;
  128. drupal_process_form($form_id, $form, $form_state);
  129. $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
  130. return $form;
  131. }
  132. /**
  133. * Implements hook_init() to add module css.
  134. */
  135. function ahah_example_init() {
  136. drupal_add_css(drupal_get_path('module', 'ahah_example') . '/ahah_example.css');
  137. }
  138. /**
  139. * @} End of "defgroup ahah_example".
  140. */
Login or register to post comments