function ajax_form_callback

7.x ajax.inc ajax_form_callback()

Menu callback; handles Ajax requests for the #ajax Form API property.

This rebuilds the form from cache and invokes the defined #ajax['callback'] to return an Ajax command structure for JavaScript. In case no 'callback' has been defined, nothing will happen.

The Form API #ajax property can be set both for buttons and other input elements.

This function is also the canonical example of how to implement #ajax['path']. If processing is required that cannot be accomplished with a callback, re-implement this function and set #ajax['path'] to the enhanced function.

See also

system_menu()

Related topics

1 string reference to 'ajax_form_callback'
system_menu in drupal/modules/system/system.module
Implements hook_menu().

File

drupal/includes/ajax.inc, line 368
Functions for use with Drupal's Ajax framework.

Code

function ajax_form_callback() {
  list($form, $form_state) = ajax_get_form();
  drupal_process_form($form['#form_id'], $form, $form_state);

  // We need to return the part of the form (or some other content) that needs
  // to be re-rendered so the browser can update the page with changed content.
  // Since this is the generic menu callback used by many Ajax elements, it is
  // up to the #ajax['callback'] function of the element (may or may not be a
  // button) that triggered the Ajax request to determine what needs to be
  // rendered.
  if (!empty($form_state['triggering_element'])) {
    $callback = $form_state['triggering_element']['#ajax']['callback'];
  }
  if (!empty($callback) && function_exists($callback)) {
    return $callback($form, $form_state);
  }
}