ajax_get_form

Versions
mediamosa-21
ajax_get_form()

Get a form submitted via #ajax during an AJAX callback.

This will load a form from the form cache used during AJAX operations. It pulls the form info from $_POST.

Return value

An array containing the $form and $form_state. Use the list() function to break these apart:

<?php

list($form, $form_state, $form_id, $form_build_id) = ajax_get_form();

?>

Related topics

▾ 7 functions call ajax_get_form()

ajax_form_callback in includes/ajax.inc
Menu callback; handles AJAX requests for the #ajax Form API property.
book_form_update in modules/book/book.pages.inc
AJAX callback to replace the book parent select options.
file_ajax_upload in modules/file/file.module
Menu callback; Shared AJAX callback for file uploads and deletions.
_ajax_app_generate_shared_key in sites/all/modules/mediamosa/core/node/mediamosa_node_mediamosa_app.inc
Insert a random app shared key in the text block.
_ajax_browse_asset_search_parameters in sites/all/modules/mediamosa/maintenance/browse/mediamosa_maintenance_browse_asset.inc
Insert the search form into a text area.
_ajax_browse_collection_search_parameters in sites/all/modules/mediamosa/maintenance/browse/mediamosa_maintenance_browse_collection.inc
Insert the search form into a text area.
_ajax_execute_rest_call in sites/all/modules/mediamosa_development/mediamosa_development.admin.inc
Insert the output of the REST call into a text area.

Code

includes/ajax.inc, line 221

<?php
function ajax_get_form() {
  $form_state = form_state_defaults();

  $form_build_id = $_POST['form_build_id'];

  // Get the form from the cache.
  $form = form_get_cache($form_build_id, $form_state);
  if (!$form) {
    // If $form cannot be loaded from the cache, the form_build_id in $_POST
    // must be invalid, which means that someone performed a POST request onto
    // system/ajax without actually viewing the concerned form in the browser.
    // This is likely a hacking attempt as it never happens under normal
    // circumstances, so we just do nothing.
    watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING);
    drupal_exit();
  }

  // Since some of the submit handlers are run, redirects need to be disabled.
  $form_state['no_redirect'] = TRUE;

  // The form needs to be processed; prepare for that by setting a few internal
  // variables.
  $form_state['input'] = $_POST;
  $form_id = $form['#form_id'];

  return array($form, $form_state, $form_id, $form_build_id);
}
?>