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: 

Creating dynamic forms with the states system

Video loading...

Transcript language code: 

Join Drupalize.Me to watch this video

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

Log in Sign up
  • 0:07
    So we've seen forms used in a couple of ways.
  • 0:10
    We built a form with the select list and submitted it.
  • 0:12
    We built a form and used #tree to be able to inspect our values
  • 0:16
    and see how those worked inside of form_state values
  • 0:19
    when we set #tree = true, maintaining that structure of our data.
  • 0:24
    In the next example, I'd like to take a look at how we can use the state system in forms,
  • 0:29
    like this one where I've got a checkbox that I can click on, that when I do click on it,
  • 0:34
    it will show other fields on the same form, so like dependent fields on our form.
  • 0:41
    In order to do that, I'm going to create a new page.
  • 0:43
    So I'm going to go back to .module file, I'm going to create a new menu item.

Creating Dynamic Forms with the States System


This video shows the basic syntax for creating form dependencies with the states system. For a more information about the states system, then be sure to check out JavaScript form dependencies with the States System.

Note: There is a typo in the code used in this video. The function form_fun_states_form() is missing a parameter, and should be: function form_fun_states_form($form, &$form_state).

Log in or sign up to download companion files.

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