| Versions | |
|---|---|
| 4.7 | drupal_validate_form($form_id, $form, |
| 5 | drupal_validate_form($form_id, $form) |
| 6 | drupal_validate_form($form_id, $form, &$form_state) |
| 7 | drupal_validate_form($form_id, &$form, &$form_state) |
Validates user-submitted form data from a global variable using the validate functions defined in a structured form array.
$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.
includes/
<?php
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;
}
?>