You are here

function drupal_validate_form in Drupal 5

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

Validates user-submitted form data from a global variable using the validate functions defined in a structured form array.

Parameters

$form_id: A unique string identifying the form for validation, submission, theming, and hook_form_alter functions.

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

Related topics

3 calls to drupal_validate_form()
comment_form_add_preview in modules/comment/comment.module
drupal_process_form in includes/form.inc
This function is the heart of form API. The form gets built, validated and in appropriate cases, submitted.
node_form_add_preview in modules/node/node.module

File

includes/form.inc, line 382

Code

function drupal_validate_form($form_id, $form) {
  global $form_values;
  static $validated_forms = array();
  if (isset($validated_forms[$form_id])) {
    return;
  }

  // If the session token was set by drupal_prepare_form(), ensure that it
  // matches the current user's session.
  if (isset($form['#token'])) {
    if (!drupal_valid_token($form_values['form_token'], $form['#token'])) {

      // Setting this error will cause the form to fail validation.
      form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
    }
  }
  _form_validate($form, $form_id);
  $validated_forms[$form_id] = TRUE;
}