Example: Form API

  1. drupal
    1. 8
    2. 6
    3. 7

Examples demonstrating the Drupal Form API.

The Form Example module is a part of the Examples for Developers Project and provides various Drupal Form API Examples. You can download and experiment with this code at the Examples for Developers project page.

Functions & methods

NameDescription
form_example_element_infoImplements hook_element_info(). *
form_example_helpImplements hook_help() to provide a bit of help.
form_example_intro
form_example_menuImplements hook_menu() to set up the URLs (menu entries) for the form examples.
form_example_states_formThis form shows off the #states system by dynamically showing parts of the form based on the state of other parts.
form_example_themeImplements hook_theme(). *
form_example_tutorialMain Form tutorial page.
form_example_tutorial_1This first form function is from the Form Tutorial handbook page
form_example_tutorial_10Example 10: A form with a file upload field.
form_example_tutorial_2This is Example 2, a basic form with a submit button.
form_example_tutorial_3Example 3: A basic form with fieldsets.
form_example_tutorial_4Example 4: Basic form with required fields.
form_example_tutorial_5Example 5: Basic form with additional element attributes.
form_example_tutorial_7Example 7: With a submit handler.
form_example_tutorial_8Example 8: A simple multistep form with a Next and a Back button.
form_example_tutorial_9Example 9: A form with a dynamically added new fields.
form_example_wizardThe primary formbuilder function for the wizard form. This is the form that you should call with drupal_get_form() from your code, and it will include the rest of the step forms defined. You are not required to change this function, as this will…
form_example_wizard_location_infoReturns form elements for the 'location info' page of the wizard. This is the second step of the wizard. This step asks for a textfield value: a City. This step also includes a validation declared later.
form_example_wizard_location_info_validateCustom validation form for the 'location info' page of the wizard.
form_example_wizard_next_submitSubmit handler for the 'next' button.
form_example_wizard_other_infoReturns form elements for the 'other info' page of the wizard. This is the thid and last step of the example wizard.
form_example_wizard_personal_infoReturns form elements for the 'personal info' page of the wizard. This is the first step of the wizard, asking for two textfields: first name and last name.
form_example_wizard_previous_submitSubmit handler for the "previous" button.
form_example_wizard_submitWizard form submit handler.
_form_example_stepsReturns the list of steps and their associated forms. This has been separated to clarify and easy the understanding of this example. You should edit this function to include the steps your wizard/multistep form requires.

examples/form_example/form_example.module, line 8