function form_execute_handlers

Executes custom validation and submission handlers for a given form.

Button-specific handlers are checked first. If none exist, the function falls back to form-level handlers.

Parameters

$type: The type of handler to execute. 'validate' or 'submit' are the defaults used by Form API.

$form: An associative array containing the structure of the form.

$form_state: A keyed array containing the current state of the form. If the user submitted the form by clicking a button with custom handler functions defined, those handlers will be stored here.

Related topics

4 calls to form_execute_handlers()
drupal_process_form in drupal/core/includes/form.inc
Processes a form submission.
EntityFormController::validate in drupal/core/lib/Drupal/Core/Entity/EntityFormController.php
Implements Drupal\Core\Entity\EntityFormControllerInterface::validate().
EntityFormControllerNG::validate in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::validate().
_form_validate in drupal/core/includes/form.inc
Performs validation on form elements.

File

drupal/core/includes/form.inc, line 1472
Functions for form and batch generation and processing.

Code

function form_execute_handlers($type, &$form, &$form_state) {
  $return = FALSE;

  // If there was a button pressed, use its handlers.
  if (isset($form_state[$type . '_handlers'])) {
    $handlers = $form_state[$type . '_handlers'];
  }
  elseif (isset($form['#' . $type])) {
    $handlers = $form['#' . $type];
  }
  else {
    $handlers = array();
  }
  foreach ($handlers as $function) {

    // Check if a previous _submit handler has set a batch, but make sure we
    // do not react to a batch that is already being processed (for instance
    // if a batch operation performs a drupal_form_submit()).
    if ($type == 'submit' && ($batch =& batch_get()) && !isset($batch['id'])) {

      // Some previous submit handler has set a batch. To ensure correct
      // execution order, store the call in a special 'control' batch set.
      // See _batch_next_set().
      $batch['sets'][] = array(
        'form_submit' => $function,
      );
      $batch['has_form_submits'] = TRUE;
    }
    else {
      call_user_func_array($function, array(
        &$form,
        &$form_state,
      ));
    }
    $return = TRUE;
  }
  return $return;
}