Blog

A Closer Look at Entity Forms

Chaz Chumley

Technology Manager, Forum One

Almost every project we work on requires a method for capturing user information. In most cases we have a Contact form and in more general purposes the client requires additional forms for various reasons. In the past, our go-to for creating forms was the Webforms module. As requirements have changed, so has the need for a web form solution that is exportable using Features.

In this series, I will be walking you through an introduction to Entity Forms, including installing, configuring and creating an Entity Form from scratch. Later we will explore Exporting Entity Forms using Features and then follow up with integrating Entity Forms with Panels.

Why not Webforms?

The drawback of using the Webform module is that there is no consistent port of this module to Drupal 8 and from an exportable solution you cannot use Features and Webform to easily migrate changes into code and onto a development or staging environment as Webforms are node based. While you could choose to use Webform Share to import and export Webform changes, this is not ideal for our development life cycle.

Advantages of using Entity Forms

This is where Entity Forms is starting to look like a more viable solution. Entity Forms if you are not familiar with them, enables the end user or developer to create front-end forms in a similar manner as Webforms. However, Entity Forms provide what I think is a more rich feature set.

  • Ability to attach any Drupal Field to the Forms
  • Ability to use most field based and entity aware modules.
  • You can download submitted data to XML and / or CSV data files using View Data Export.
  • Rules based form submission notifications. Allows for complex notifications logic.
  • Rules based form access control. Allows for complex access logic.
  • Use Views to create to an administrative listing of each Entityform type Submissions for fine grain control.

The Entity form module takes advantage of the Entity API, allowing for use of the Field UI and some consistency with how we are already developing. Oh, and they are exportable as well using Features, which make placing them in code advantageous for continuous integration.

Installing Entity Forms

Like most modules, Entity Forms can be found at Drupal.org and downloaded by browsing to (https://drupal.org/project/entityform). Feel free to choose the download version that is right for you. For sake of demonstration, I will be using the 7.x-2.0-beta2 version along with Drush to download the module into my “sites/all/modules/contrib” folder.

Note: If you do not have a “contrib” folder under your “modules” directory, you can create one or simply place the downloaded module directly into the “modules” folder.

One we have the module downloaded we need to navigate to “admin/modules” and enable the “Entityforms” module. Keep in mind that Entityforms has dependencies of “Entity API, Views, Chaos tools, Field UI, Field and Field SQL storage”, so you will also need to download and install the dependencies. If you want to have Forms send email to users you will also need to download and install the Rules module and finally since Entityforms uses the Fields UI, you may want to download and configure the “Email Field” module.

Configuring Entity Forms

Entityforms work much like that of a Content type in that you can configure them by creating an entityform type and add fields to it. If we navigate to “admin/structure/entityform_types” we can begin to create a new Entityform as shown in the following image.

Entity Forms

Creating an Entity Form

For demonstration purposes, we will create a new “Contact” form. To begin creating an Entityform click on “Add entityform type” and fill out the fields as shown in the following image.

Entity Forms

  1. Name – Human readable name of our form.
  2. Redirect path – Relative path that a user is redirected to upon submission.
  3. Intro form instructions – User instructions you want to display.

We now are presented with multiple settings on how our new form will function. We will need to complete some or all of these sections so let’s review those now.

Access settings

Access settings control who can submit a form, whether a form is open for submissions and whether a form can be resubmitted by the same user. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. Form status – Can users submit the form. Value allows for form submission to be open or closed.
  2. Roles – Roles that can submit our new form.
  3. Resubmit action – Action to take if logged in user has already submitted our form.

Submission page settings

Submission settings control the page title and response that a user will see upon successfully submitting a form. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. Preview Page – Boolean value to show a preview page to user when they are about to submit a form.
  2. Submission page title – Page title displayed after form is submitted.
  3. Submission reply – The text that will be displayed to user upon form submission.
  4. Show submission information – Boolean value to show user submission form data.

Submission views

Submission views allow you to specify the view used to display submission reports to both the admin and end user. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. View for submission reports – Select the view that should be used for Submission reports. These views are customizable.
  2. View for current user’s submissions – Select the view that should be used to show users their previous submissions.

Draft settings

Draft settings control whether a form can have multiple drafts prior to actually submitting it. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. Draftable – Boolean value to specify whether a user can save a draft of the form.
  2. Override drat button text – Text to use for draft save button.
  3. Draft save text – Text to be displayed to user when the form is saved as a draft.

Menu settings

Menu settings control whether a form has a link on a specific menu for user to navigate to. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. Provide a menu link – Boolean value to provide a menu link for form.
  2. Menu link title – Title of menu link that will be displayed.
  3. Description – Alt or Title attribute that will display when hovering over menu link.
  4. Parent item – Menu that men link will belong to.
  5. Weight – Specified order of menu link within menu.

URL path settings

URL path settings control the url alias for both submitting the form and the confirmation page once a form has been submitted. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. Submit URL alias – URL where user can find the form.
  2. Confirm URL alias – URL user is taken to upon submitting the form. This will display a page with the settings from the “Submission page settings”.

Form overrides

Form overrides allow you to change some of the default values of the form including the submit button text, confirmation text and titles. The controls contain the following fields and you can view the defaults I have selected in the following image.

Entity Forms

  1. Submit Button Text – Text to use for submit button
  2. Submission Confirmation Text – Text to use for Submission Confirmation
  3. Your Submissions Text – Text to use for “Your Submissions” page
  4. Form Disallow Resubmit Text – Text to use for “You already submitted this form”
  5. Submission Delete Text –Text to use for “Delete Confirmation”
  6. Submission View Title – Text to use for page title of submission view

Now that we have configured our Contact form we need to add fields to it for the user to be able to input information that will be submitted. Since Entityforms utilizes the Fields UI, we should be pretty comfortable in adding fields.

Managing fields

To manage fields we need to simply navigate to the “Manage Fields” tab and add our fields as shown in the following image.

Entity Forms

For our particular Contact form we added the following fields.

  1. Name – Text field with the default settings.
  2. Email – Email field with the default settings.
  3. Subject – Text field with the default settings.
  4. Message – Long text field with the default settings.

Finally, let’s preview what our form look like by browsing to the Contact link we provided earlier in our settings as shown in the following image.

Entity Forms

Summary

We covered a lot of information in a short period of time. Including how to download and install the Entityforms module and the dependencies it has to configure properly. We looked at configuring a new Entityform with proper settings and finished off by adding the fields through the Fields UI and previewing our new form. Next time we will look at configuring the Rules module for allowing Entityforms to notify uses by emailing them that a form has been submitted.

Written By

Chaz Chumley

Technology Manager, Forum One