
Once complete the page should look like the image below: You can disable them by dragging them into the “Disabled” area. Move “Drupal version” to the top, then disable “Subject” and “Send copy to sender”. Click on the “Manage form display” tab.Ģ. Let’s now configure the field widgets which’ll be displayed on the form.ġ. I discuss the difference between fields and widgets in part one: “ Build a Blog in Drupal 8: Content types and Fields“ New in Drupal 8 is the separation between the field and its widget. Finally, let’s make the field mandatory by checking “Required field”, then click “Save settings”. Enter in the following values into “Allowed values list”. Click on “Add field”, then select “List (text)” from “Add a new field” and add “Drupal version” to the Label field.ģ. Go to Structure, “Contact forms” and click on “Manage fields” from the Edit drop-down.Ģ.
DRUPAL 8 FORM API EXAMPLE HOW TO
If you know how to add fields to them, you’ll know how to add them to contact forms.ġ. So let’s add a drop-down list which let’s users select a Drupal version.Īdding fields to the contact form is the same as adding one to a content type or block type. In Drupal 8, contact forms are fieldable. You’ll notice that the form already has a few default fields.Įach contact form will have the following:Įven though these are the default fields, you can disable them from the “Manage form display” page so they won’t be shown. Now click on “Drupal question” to see the form. You should’ve been redirected back to the “Contact forms” page. Once the form has been filled out, scroll to the bottom and click on Save.ģ. Enter “Drupal question” into Label and enter in an email address into Recipients. Go to Structure, “Contact forms” and click on “Add contact form”.Ģ. This is great because you can create custom forms directly in core without installing extra modules.ġ. Custom Contact FormĪs mentioned in the introduction, contact forms in Drupal 8 are now fieldable. When the form is filled out an email is sent to a designated email address. This form is used as the basic site-wide contact form and a link is displayed in the footer.
DRUPAL 8 FORM API EXAMPLE INSTALL
This will let the user select a version of Drupal from a drop-down list.Ī default form called “Website feedback” is created when you install Drupal using the Standard installation profile. This form will be similar to the standard contact form but we’ll add an extra field called “Drupal version”. So in this tutorial, we’ll create a custom contact form called “Drupal question”. This means you can add any custom field to them and this let’s you create proper, albeit basic forms. Following in good old Drupal tradition, these contact form types are fieldable.

Instead of having a single form, you can now create different contact form types. You can create different categories but the form stays the same. One limitation in Drupal 7 is you can’t modify the fields on the form. When a user fills them out, an email is sent to configured email addresses. In Drupal 7, the Contact module is used to create basic contact forms.

Let’s now build on this by creating a few contact forms.

In the last tutorial, we added a few menus to flesh out the site navigation. This tutorial is part of the “Build a Blog in Drupal 8” series:
