Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Altering specific forms and customizing validation

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    So there's another way you can change someone else's form.
  • 0:11
    I just previously discussed hook_form_alter which is called on all forms,
  • 0:15
    which is why we need to use that switch statement.
  • 0:17
    But there's also hook_form_FORM_ID_alter,
  • 0:22
    which only gets called for that specific form ID.
  • 0:26
    So I'd like to show you another example.
  • 0:29
    Let's go back and use our hook_form_alter
  • 0:34
    just to get the form_id.
  • 0:36
    So we know what to put in place.
  • 0:38
    I'm going to go ahead and comment out my $form as well.

Altering Specific Forms and Customizing Validation

Loading...

This video shows how to target a specific form with the hook_form_FORM_ID_alter and creating a customized validation function for a form.

Note: There is a typo in this video. (The code is correct in the downloadable example file attached to the previous video.)

In the demo_validate_password() function, the following line shown in the video if (in_array($form['values']['pass'], $badpasswords)) { should be if (in_array($form_state['values']['pass'], $badpasswords)) {.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.