form_test.file.inc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * An include file to test loading it with the form API.
  5. */
  6. /**
  7. * Form constructor for testing FAPI file inclusion of the file specified in
  8. * hook_menu().
  9. */
  10. function form_test_load_include_menu($form, &$form_state) {
  11. // Submit the form via Ajax. That way the FAPI has to care about including
  12. // the file specified in hook_menu().
  13. $ajax_wrapper_id = drupal_html_id('form-test-load-include-menu-ajax-wrapper');
  14. $form['ajax_wrapper'] = array(
  15. '#markup' => '<div id="' . $ajax_wrapper_id . '"></div>',
  16. );
  17. $form['button'] = array(
  18. '#type' => 'submit',
  19. '#value' => t('Save'),
  20. '#submit' => array('form_test_load_include_submit'),
  21. '#ajax' => array(
  22. 'wrapper' => $ajax_wrapper_id,
  23. 'method' => 'append',
  24. 'callback' => 'form_test_load_include_menu_ajax',
  25. ),
  26. );
  27. return $form;
  28. }
  29. /**
  30. * Submit callback for the form API file inclusion test forms.
  31. */
  32. function form_test_load_include_submit($form, $form_state) {
  33. drupal_set_message('Submit callback called.');
  34. }
  35. /**
  36. * Ajax callback for the file inclusion via menu test.
  37. */
  38. function form_test_load_include_menu_ajax($form) {
  39. // We don't need to return anything, since #ajax['method'] is 'append', which
  40. // does not remove the original #ajax['wrapper'] element, and status messages
  41. // are automatically added by the Ajax framework as long as there's a wrapper
  42. // element to add them to.
  43. return '';
  44. }