A Closer Look at Entity Forms
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 an on to 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 lfe 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.
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.
-
Name - Human readable name of our form.
-
Redirect path - Relative path that a user is redirected to upon submission..
-
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.
-
Form status - Can users submit the form. Value allows for form submission to be open or closed.
-
Roles - Roles that can submit our new form.
-
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.
-
Preview Page - Boolean value to show a preview page to user when they are about to submit a form.
-
Submission page title - Page title displayed after form is submitted.
-
Submission reply - The text that will be displayed to user upon form submission.
-
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.
-
View for submission reports - Select the view that should be used for Submission reports. These views are customizable.
-
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.
-
Draftable - Boolean value to specify whether a user can save a draft of the form.
-
Override drat button text - Text to use for draft save button.
-
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.
-
Provide a menu link - Boolean value to provide a menu link for form.
-
Menu link title - Title of menu link that will be displayed.
-
Description - Alt or Title attribute that will display when hovering over menu link.
-
Parent item - Menu that men link will belong to.
-
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.
-
Submit URL alias - URL where user can find the form.
-
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 allows 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.
-
Submit Button Text – Text to use for submit button
-
Submission confirmation Text – Text to use for Submission Confirmation
-
Your Submissions Text – Text to use for “Your Submissions” page
-
Form Disallow Resubmit Text – Text to use for “You already submitted this form”
-
Submission Delete Text –Text to use for “Delete Confirmation”
-
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.
For our particular Contact form we added the following fields.
-
Name - Text field with the default settings.
-
Email - Email field with the default settings.
-
Subject - Text field with the default settings.
-
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.
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.
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 we will be walking taking a closer look at Entityforms.