You are here

function drupal_process_form in Drupal 5

Same name and namespace in other branches
  1. 6 includes/form.inc \drupal_process_form()
  2. 7 includes/form.inc \drupal_process_form()

This function is the heart of form API. The form gets built, validated and in appropriate cases, submitted.

Parameters

$form_id: The unique string identifying the current form.

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

Return value

The path to redirect the user to upon completion.

Related topics

2 calls to drupal_process_form()
drupal_execute in includes/form.inc
Retrieves a form using a form_id, populates it with $form_values, processes it, and returns any validation errors encountered. This function is the programmatic counterpart to drupal_get_form().
drupal_get_form in includes/form.inc
Retrieves a form from a builder function, passes it on for processing, and renders the form or redirects to its destination as appropriate. In multi-step form scenarios, it handles properly processing the values using the previous step's form…

File

includes/form.inc, line 238

Code

function drupal_process_form($form_id, &$form) {
  global $form_values, $form_submitted, $user, $form_button_counter;
  static $saved_globals = array();

  // In some scenarios, this function can be called recursively. Pushing any pre-existing
  // $form_values and form submission data lets us start fresh without clobbering work done
  // in earlier recursive calls.
  array_push($saved_globals, array(
    $form_values,
    $form_submitted,
    $form_button_counter,
  ));
  $form_values = array();
  $form_submitted = FALSE;
  $form_button_counter = array(
    0,
    0,
  );
  drupal_prepare_form($form_id, $form);
  if ($form['#programmed'] || !empty($_POST) && $_POST['form_id'] == $form_id) {
    drupal_validate_form($form_id, $form);

    // IE does not send a button value when there is only one submit button (and no non-submit buttons)
    // and you submit by pressing enter.
    // In that case we accept a submission without button values.
    if (($form['#programmed'] || $form_submitted || !$form_button_counter[0] && $form_button_counter[1]) && !form_get_errors()) {
      $redirect = drupal_submit_form($form_id, $form);
      if (!$form['#programmed']) {
        drupal_redirect_form($form, $redirect);
      }
    }
  }

  // We've finished calling functions that alter the global values, so we can
  // restore the ones that were there before this function was called.
  list($form_values, $form_submitted, $form_button_counter) = array_pop($saved_globals);
  return $redirect;
}