'AJAX Example', 'page callback' => 'ajax_example_intro', 'access callback' => TRUE, 'expanded' => TRUE, ); // Change the description of a form element. $items['examples/ajax_example/simplest'] = array( 'title' => 'Simplest AJAX Example', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_simplest'), 'access callback' => TRUE, 'weight' => 0, ); // Generate a changing number of checkboxes. $items['examples/ajax_example/autocheckboxes'] = array( 'title' => 'Generate checkboxes', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_autocheckboxes'), 'access callback' => TRUE, 'weight' => 1, ); // Generate different textfields based on form state. $items['examples/ajax_example/autotextfields'] = array( 'title' => 'Generate textfields', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_autotextfields'), 'access callback' => TRUE, 'weight' => 2, ); // Submit a form without a page reload. $items['examples/ajax_example/submit_driven_ajax'] = array( 'title' => 'Submit-driven AJAX', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_submit_driven_ajax'), 'access callback' => TRUE, 'weight' => 3, ); // Repopulate a dropdown based on form state. $items['examples/ajax_example/dependent_dropdown'] = array( 'title' => 'Dependent dropdown', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_dependent_dropdown'), 'access callback' => TRUE, 'weight' => 4, ); // Repopulate a dropdown, but this time with graceful degredation. // See ajax_example_graceful_degradation.inc. $items['examples/ajax_example/dependent_dropdown_degrades'] = array( 'title' => 'Dependent dropdown (with graceful degradation)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_dependent_dropdown_degrades'), 'access callback' => TRUE, 'weight' => 5, 'file' => 'ajax_example_graceful_degradation.inc', ); // The above example as it appears to users with no javascript. $items['examples/ajax_example/dependent_dropdown_degrades_no_js'] = array( 'title' => 'Dependent dropdown with javascript off', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_dependent_dropdown_degrades', TRUE), 'access callback' => TRUE, 'file' => 'ajax_example_graceful_degradation.inc', 'weight' => 5, ); // Populate a form section based on input in another element. $items['examples/ajax_example/dynamic_sections'] = array( 'title' => 'Dynamic Sections (with graceful degradation)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_dynamic_sections'), 'access callback' => TRUE, 'weight' => 6, 'file' => 'ajax_example_graceful_degradation.inc', ); // The above example as it appears to users with no javascript. $items['examples/ajax_example/dynamic_sections_no_js'] = array( 'title' => 'Dynamic Sections w/JS turned off', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_dynamic_sections', TRUE), 'access callback' => TRUE, 'weight' => 6, 'file' => 'ajax_example_graceful_degradation.inc', ); // A classic multi-step wizard, but with no page reloads. // See ajax_example_graceful_degradation.inc. $items['examples/ajax_example/wizard'] = array( 'title' => 'Wizard (with graceful degradation)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_wizard'), 'access callback' => TRUE, 'file' => 'ajax_example_graceful_degradation.inc', 'weight' => 7, ); // The above example as it appears to users with no javascript. $items['examples/ajax_example/wizard_no_js'] = array( 'title' => 'Wizard w/JS turned off', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_wizard', TRUE), 'access callback' => TRUE, 'file' => 'ajax_example_graceful_degradation.inc', 'weight' => 7, ); // Add-more button that creates additional form elements. // See ajax_example_graceful_degradation.inc. $items['examples/ajax_example/add_more'] = array( 'title' => 'Add-more button (with graceful degradation)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_add_more'), 'access callback' => TRUE, 'file' => 'ajax_example_graceful_degradation.inc', 'weight' => 8, ); // The above example as it appears to users with no javascript. $items['examples/ajax_example/add_more_no_js'] = array( 'title' => 'Add-more button w/JS turned off', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_add_more', TRUE), 'access callback' => TRUE, 'file' => 'ajax_example_graceful_degradation.inc', 'weight' => 8, ); // Use the AJAX framework outside the context of a form using the use-ajax // class. See ajax_example_misc.inc. $items['examples/ajax_example/ajax_link'] = array( 'title' => 'Ajax Link ("use-ajax" class)', 'page callback' => 'ajax_example_render_link', 'access callback' => TRUE, 'file' => 'ajax_example_misc.inc', 'weight' => 9, ); // Use the AJAX framework outside the context of a form using a renderable // array of type link with the #ajax property. See ajax_example_misc.inc. $items['examples/ajax_example/ajax_link_renderable'] = array( 'title' => 'Ajax Link (Renderable Array)', 'page callback' => 'ajax_example_render_link_ra', 'access callback' => TRUE, 'file' => 'ajax_example_misc.inc', 'weight' => 9, ); // A menu callback is required when using ajax outside of the Form API. $items['ajax_link_callback'] = array( 'page callback' => 'ajax_link_response', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, 'file' => 'ajax_example_misc.inc', ); // Use AJAX framework commands outside of the #ajax form property. // See ajax_example_advanced.inc. $items['examples/ajax_example/advanced_commands'] = array( 'title' => 'AJAX framework commands', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_advanced_commands'), 'access callback' => TRUE, 'file' => 'ajax_example_advanced.inc', 'weight' => 100, ); // Autocomplete examples. $items['examples/ajax_example/simple_autocomplete'] = array( 'title' => 'Autocomplete (simple)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_simple_autocomplete'), 'access arguments' => array('access user profiles'), 'file' => 'ajax_example_autocomplete.inc', 'weight' => 10, ); $items['examples/ajax_example/simple_user_autocomplete_callback'] = array( 'page callback' => 'ajax_example_simple_user_autocomplete_callback', 'file' => 'ajax_example_autocomplete.inc', 'type' => MENU_CALLBACK, 'access arguments' => array('access user profiles'), ); $items['examples/ajax_example/node_autocomplete'] = array( 'title' => 'Autocomplete (node with nid)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_unique_autocomplete'), 'access arguments' => array('access content'), 'file' => 'ajax_example_autocomplete.inc', 'weight' => 11, ); $items['examples/ajax_example/unique_node_autocomplete_callback'] = array( 'page callback' => 'ajax_example_unique_node_autocomplete_callback', 'file' => 'ajax_example_autocomplete.inc', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), ); $items['examples/ajax_example/node_by_author'] = array( 'title' => 'Autocomplete (node limited by author)', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_node_by_author_autocomplete'), 'access callback' => TRUE, 'file' => 'ajax_example_autocomplete.inc', 'weight' => 12, ); $items['examples/ajax_example/node_by_author_autocomplete'] = array( 'page callback' => 'ajax_example_node_by_author_node_autocomplete_callback', 'file' => 'ajax_example_autocomplete.inc', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), ); // This is the landing page for the progress bar example. It uses // drupal_get_form() in order to build the form. $items['examples/ajax_example/progressbar'] = array( 'title' => 'Progress bar example', 'page callback' => 'drupal_get_form', 'page arguments' => array('ajax_example_progressbar_form'), 'access arguments' => array('access content'), 'file' => 'ajax_example_progressbar.inc', ); // This is the callback route for the AJAX-based progress bar. $items['examples/ajax_example/progressbar/progress/%'] = array( 'title' => 'Progress bar progress', 'page callback' => 'ajax_example_progressbar_progress', 'page arguments' => array(4), 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), 'file' => 'ajax_example_progressbar.inc', ); return $items; } /** * A basic introduction page for the ajax_example module. */ function ajax_example_intro() { $markup = t('The AJAX example module provides many examples of AJAX including forms, links, and AJAX commands.'); $list[] = l(t('Simplest AJAX Example'), 'examples/ajax_example/simplest'); $list[] = l(t('Generate checkboxes'), 'examples/ajax_example/autocheckboxes'); $list[] = l(t('Generate textfields'), 'examples/ajax_example/autotextfields'); $list[] = l(t('Submit-driven AJAX'), 'examples/ajax_example/submit_driven_ajax'); $list[] = l(t('Dependent dropdown'), 'examples/ajax_example/dependent_dropdown'); $list[] = l(t('Dependent dropdown (with graceful degradation)'), 'examples/ajax_example/dependent_dropdown_degrades'); $list[] = l(t('Dynamic Sections w/JS turned off'), 'examples/ajax_example/dependent_dropdown_degrades_no_js'); $list[] = l(t('Wizard (with graceful degradation)'), 'examples/ajax_example/wizard'); $list[] = l(t('Wizard w/JS turned off'), 'examples/ajax_example/wizard_no_js'); $list[] = l(t('Add-more button (with graceful degradation)'), 'examples/ajax_example/add_more'); $list[] = l(t('Add-more button w/JS turned off'), 'examples/ajax_example/add_more_no_js'); $list[] = l(t('Ajax Link ("use-ajax" class)'), 'examples/ajax_example/ajax_link'); $list[] = l(t('Ajax Link (Renderable Array)'), 'examples/ajax_example/ajax_link_renderable'); $list[] = l(t('AJAX framework commands'), 'examples/ajax_example/advanced_commands'); $list[] = l(t('Autocomplete (simple)'), 'examples/ajax_example/simple_autocomplete'); $list[] = l(t('Autocomplete (node with nid)'), 'examples/ajax_example/node_autocomplete'); $list[] = l(t('Autocomplete (node limited by author)'), 'examples/ajax_example/node_by_author'); $variables['items'] = $list; $variables['type'] = 'ul'; $markup .= theme('item_list', $variables); return $markup; } /** * Basic AJAX callback example. * * Simple form whose ajax-enabled 'changethis' member causes a text change * in the description of the 'replace_textfield' member. * * See @link http://drupal.org/node/262422 Form API Tutorial @endlink */ function ajax_example_simplest($form, &$form_state) { $form = array(); $form['changethis'] = array( '#title' => t("Choose something and explain why"), '#type' => 'select', '#options' => array( 'one' => 'one', 'two' => 'two', 'three' => 'three', ), '#ajax' => array( // #ajax has two required keys: callback and wrapper. // 'callback' is a function that will be called when this element changes. 'callback' => 'ajax_example_simplest_callback', // 'wrapper' is the HTML id of the page element that will be replaced. 'wrapper' => 'replace_textfield_div', // There are also several optional keys - see ajax_example_autocheckboxes // below for details on 'method', 'effect' and 'speed' and // ajax_example_dependent_dropdown for 'event'. ), ); // This entire form element will be replaced whenever 'changethis' is updated. $form['replace_textfield'] = array( '#type' => 'textfield', '#title' => t("Why"), // The prefix/suffix provide the div that we're replacing, named by // #ajax['wrapper'] above. '#prefix' => '