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, submitting and validating a simple form

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:07
    In order to demonstrate using Drupal's Form API,
  • 0:10
    we're going to build a couple of different forms.
  • 0:12
    The first one is going to look like this.
  • 0:14
    We're going to have a form that asks a simple question, would you like cake or pie?
  • 0:18
    And you can choose from the select list, "Cake please" or "Pie I guess."
  • 0:23
    In addition to the select list, you'll get a Submit button,
  • 0:26
    which you can use to submit the form or an Equivocate button,
  • 0:29
    which you can click on if you prefer not to answer the question.
  • 0:33
    If you choose cake from the list and click Submit,
  • 0:36
    you'll get a warning, "Sorry, we're out of cake."

Creating, Submitting and Validating a Simple Form

Loading...

This videos goes through the process of creating a form with Drupal Forms API that is single select list that has a validation, submission and redirect functionality.

NOTE:

Their is a typo in the code displayed in the video. The function

function form_fun_cake(&$form_state)

is missing the $form paramater and should instead be

function form_fun_cake($form, &$form_state)

Curious about when you're supposed to translate "title" and when you should leave it alone? Here's the answer: You don't need to translate the 'title' attribute of an array that defines a menu item because Drupal will take care of that automatically. In fact, you shouldn't translate those as they'll end up getting double translated if you do. This is because Drupal end's up using this string of text in a number of different ways some of which don't actually need to be translated and others that do like for example when it's the title of a page or the text of a link in the menu system. The #title (and #description) property for elements in Form API array however are your responsibility to translate.

Downloads: 
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.