function hook_validate

Validates form submissions from the Form API

This function can be named anything you want (or can be considered optional). If named the same thing as the form callback, it will be utilized automatically. For example, if you form is named my_form, then if you have a validate function named my_form_validate, it will be called automatically.

Since $form_state is passed by reference, you may make changes to this array, and those changes will carry through to other validate functions (defined with #validate_handlers) and then to the submit handler(s).

See also

hook_submit($form, &$form_state)

5 functions implement hook_validate()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

form_basic_validate in includes/forms.inc
This is a very basic valiator for form API submission. All I really care about is making sure required fields have a value in them. If they do not, we will file a form_error.
system_login_form_validate in modules/system/system.module
Validate function for the login form. This is where we will do all of the lookups to verify username and password. If you want to write your own login handler (like for LDAP) this is the function you would duplicate in a custom module, then use…
system_school_data_form_validate in modules/system/system.module
Validate handler for the school_data_form.
user_edit_student_user_form_validate in modules/user/user.module
Validate handler for editing student users.
user_edit_user_form_validate in modules/user/user.module
Validate handler for editing faculty users.

File

includes/hook.api.php, line 95
Lists all available hooks within FlightPath's core code.

Code

function hook_validate($form, &$form_state) {
  $age = $form_state ["values"]["age"];
  if ($age < 18) {
    form_error("age", "Sorry, you must be 18 or older to submit this form.");
    return;
  }
}