| Versionen | |
|---|---|
| drupal7 | form_ahah_callback() |
Menu callback for AHAH callbacks through the #ahah['callback'] FAPI property.
includes/
<?php
function form_ahah_callback() {
$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/ahah 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.
exit;
}
// We will run some of the submit handlers so we need to disable redirecting.
$form['#redirect'] = FALSE;
// We need to process the form, prepare for that by setting a few internals
// variables.
$form_state['input'] = $_POST;
$form_state['args'] = $form['#args'];
$form_id = $form['#form_id'];
// Build, validate and if possible, submit the form.
drupal_process_form($form_id, $form, $form_state);
// This call recreates the form relying solely on the form_state that the
// drupal_process_form set up.
$form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
// Get the callback function from the clicked button.
$callback = $form_state['clicked_button']['#ahah']['callback'];
if (drupal_function_exists($callback)) {
$callback($form, $form_state);
}
}
?>
Kommentare
Kommentar hinzufügen