Fields
Freeform features its own set of robust field types. The form builder displays a list of available field types which can then be added to forms indefinitely. Fields are specific to each form, but can also be saved as favorites or searched upon to be reused in other forms.
Overview
Standard Settings
There is a standard number of settings available to all forms (with some exceptions). Every form field has the ability for you to do the following:
Setting | Template Usage | Description |
---|---|---|
Label | label | The label for the field. This can be changed per form if you wish. |
Handle | handle | How the field may be called in templates, if necessary. You may also override this value per form if you wish. |
Required | required | Toggle if the field requires a value to submit the form successfully. |
Custom Validation ErrorNew in 5.7+ | Visible when Required is toggled on. If this field is left empty upon submit, show this error message. | |
Instructions | instructions | Specify intructions for the field if you wish. |
Default Value | defaultValue | For applicable fields, you can set a default value or selected option for the field. |
Placeholder | placeholder | Specify placeholder text for the field, if applicable. |
Maximum Length | maxlength | The maximum number of characters for the field's value. Applicable only to the following field types: |
Attribute Editor | Apply any kind of attribute on the input, label, error, instruction in Freeform's automated rendering of the form. | |
Options | options
| Specify the option labels and values for applicable field types. Available only for the following field types: |
All field types conveniently include the ability to set attributes for their labels, inputs, errors and instructions directly inside the form builder property editor.
- This allows you to keep your hands clean of being inside formatting templates and specify one-off exceptions for fields such as
readonly
andautocomplete="off"
, etc. - To use single attributes like
novalidate
, just enter the attribute in the Attribute column and leave the Value column empty. - You can use anything inside the Form and Field objects as well, e.g.:
field.id
to access Field ID.form.handle
to access form handle.
Field EncryptionProNew in 5.0+
Each field includes the ability to optionally encrypt its submission data. Simply toggle the Encrypt field data setting inside the form builder for any field you wish to have encrypted. Freeform will take care of the rest.
For each field that is encrypted and contains submission data, the database row column will contain a prefix of encrypted:
and then the encryption string. Freeform will decrypt the submission data for exports, email notifications, integrations, and viewing submission data inside the control panel and front end (if you have templates set up to show it).
Field encryption uses the Craft Security Key (usually CRAFT_SECURITY_KEY
in your .env
file), so be sure to use the same key across multiple environments.
CRAFT_SECURITY_KEY=zVtC4j25ADUxf5H14xiIAzqKoCJtyLu7
If you wish to use a different security key for Freeform specifically, you can specify a custom key in the Secret Key setting under the Form Sessions area of the Form Behavior settings page (CP -> Freeform -> Settings -> Form Behavior).
Encryption is not retroactive. Each submission will need to be resaved to update older submissions.
Populating Field OptionsLiteProImproved in 5.0+
All multi-option field types (such as Dropdown, Checkboxes, etc) can have their option labels and values automatically populated with Craft Elements or Pre-defined list options. This allows you to quickly build forms by having fields auto-generated.
Applicable Field Types
The following field types can be auto-populated:
- Dropdown
- Optional Empty Option Label to have first option be something like
Please select...
- Optional Empty Option Label to have first option be something like
- Multiple Select
- Checkboxes
- Radios
Available OptionsLitePro
The following Freeform Predefined Options and Craft Elements can be fed to the above field types:
- Dates
- Ranges
- Regions
- Languages
- Craft Elements
Months
- All 12 months of the year.
- Option Label and Option Value choices:
- Full, e.g.
September
- Abbreviated (Capitalized 3 letters), e.g.
Sep
- Single Number, e.g.
9
- 2-digit Number, e.g.
09
- Full, e.g.
Days
- List of days
1
to31
. - Option Label and Option Value choices:
- Single Number, e.g.
3
- 2-digit Number, e.g.
03
- Single Number, e.g.
Days of Week
- List of all days of week.
- Option Label and Option Value choices:
- Full, e.g.
Thursday
- Abbreviated (Capitalized 3 letters), e.g.
Thu
- Single Number, e.g.
4
- Full, e.g.
Numbers (range)
- A custom range of numbers
- Range Start and Range End
- E.g.
60
-65
would return list:60, 61, 62, 63, 64, 65
- E.g.
Years (range)
- A custom range of years
- Range Start - number of years in PAST from current year
- Range End - number of years in FUTURE from current year
- E.g.
5
(start) -0
(end) would return list:2018, 2017, 2016, 2015, 2014, 2013
- E.g.
- Sort Direction:
- Ascending
- Descending
States
- Official USA states
- Option Label and Option Value choices:
- Full
- Abbreviated (upper case 2 letters)
States & Territories
- Official USA states and territories
- Option Label and Option Value choices:
- Full
- Abbreviated (upper case 2 letters)
Canadian Provinces
- Official Canadian provinces and territories
- Provinces - English
- Canadian Provinces and territories in English
- Provinces - French
- Canadian Provinces and territories in French
- Provinces - Bilingual
- Bilingual list of Canadian Provinces and territories
- Option Label and Option Value choices:
- Full
- Abbreviated (upper case 2 letters)
Countries
- All world countries
- Option Label and Option Value choices:
- Full
- Abbreviated (upper case 2 letters)
World Languages
- All world languages
- Option Label and Option Value choices:
- Full
- Abbreviated (lower case 2 letters)
Craft Entries
- Target sections or all sections.
- Option Label and Option Value choices:
- ID, Title, Slug, URI, Fields (simple values)
Craft Users
- Target user groups or all groups.
- Option Label and Option Value choices:
- ID, Username, Email, First Name, Last Name, Full Name, Fields (simple values)
Craft Categories
- Target category groups or all groups.
- Option Label and Option Value choices:
- ID, Title, Slug, URI, Fields (simple values)
Craft Tags
- Target tag groups or all groups.
- Option Label and Option Value choices:
- ID, Title, Slug, URI, Fields (simple values)
Craft Assets
- Target asset groups or all groups.
- Option Label and Option Value choices:
- Filename, ID, Fields (simple values)
Craft Commerce Products
- Target product type or all product types.
- Option Label and Option Value choices:
- ID, Title, Slug, URI, SKU, Price, Fields (simple values)
Convert to Custom OptionsNew in 5.0+
Sometimes you need a little more control over the populated data generated by the Element or Predefined options. You can click the Convert to Custom Options button at any time to have the generated option data converted to Custom options that can then have its options edited, removed, added, renamed, and reordered.
There are potentially negative implications with using this feature:
- Your options data can become out of sync when new elements (e.g. Entries) are added after the fact.
- If you apply this when there are already existing submissions, renaming option values will orphan submissions relying on the old value name.
- Be very careful if you attempt to redo this process (e.g. changing back to Element source and grabbing a fresh list of Craft Entries, then converting back to Custom). If any existing submissions are relying on old or modified option values, they can become orphaned in the process.
Field Types
Freeform contains a rich set of field types to handle just about every possible scenario you might get yourself into.
Fields can be changed to other field types at any point, but be aware that data loss could occur when switching incompatible field types.
Name | field.type | Description | Express | Lite | Pro |
---|---|---|---|---|---|
CalculationNew in 5.1+ | calculation | Perform dynamic calculations based on user-input values within forms. | ✕ | ✕ | ✓ |
Checkbox | checkbox | A single checkbox field. | ✓ | ✓ | ✓ |
Checkboxes | checkboxes | A group of checkboxes. |