Form Data Tokens
When using Twig Templates, you can use these special tokens to access form submission data:-
{{ formresult }}
: Contains the data from the single, most recent form submission by the contact for the form that triggered the action. -
{{ formresults }}
: Contains a list (array) of all form submissions made by the contact for the triggering form. -
getFormResults(formId, contactId, limit, page, orderBy, orderDirection)
:
A Twig function to fetch form submissions for any form by its ID, with optional filters and pagination.formId
(required): The ID of the form.contactId
(optional): The contact’s ID. If omitted ornull
, fetches results for all contacts.limit
(optional): Max number of results per page.page
(optional): Page number (default: 1).orderBy
(optional): Field to sort by (default:'s.date_submitted'
).orderDirection
(optional):'ASC'
or'DESC'
(default:'DESC'
).
-
getFormResultsCount(formId, contactId)
:
A Twig function that fetches the total count of form submissions for a specific form ID.formId
: (Required) The integer ID of the Mautic Form you want to query.contactId
: (Optional) The integer ID of the Mautic Contact. If provided, counts submissions for that specific contact only. If omitted ornull
, counts submissions for the form across all contacts.- Returns an integer representing the total number of matching submissions.
- Available in Emails, SMS, and Landing Pages.
- Example (Show how many times the current contact submitted Form 12):
- Example (Show the total number of submissions for Form 12 across all contacts):
Fetching Results Count for Any Form (getFormResultsCount
)
You can use the getFormResultsCount
function to set a registration cap for a form. For example, if you want to stop accepting new registrations after a certain number of people have registered, you can use Twig logic to display a message instead of the form.
Example: Limit Registrations and Show “Registration Complete” Message
Fetching Results for Any Form (getFormResults
)
You can use the getFormResults
Twig function to fetch submissions for any form by its ID, with optional filters and pagination.
Each submission
in the results contains all the form field values, accessible by their alias (the unique name you gave the field). For example, if your form has fields with aliases firstname
, email
, and company
, you can access them as submission.firstname
, submission.email
, and submission.company
.You also get some built-in properties like
submission.dateSubmitted
and submission.leadId
.
Example: Display Recent Form Submissions in a Table
Let’s say you want to show the last 3 times a contact filled out Form 12. Here’s how:
- A table with the submission date, name, email and company
- Only the last 3 submissions
- A friendly message if no submissions exist
- A list of emails from the last 5 submissions
- The date they submitted
- A friendly message if no one has submitted yet
Using the Last Submission (formresult
)
Important: This only works if the email is sent using:
• A “Send email to contact” action directly on a form.
• A “Send email” action in a campaign that starts when a form is submitted.
• A “Send email to contact” action directly on a form.
• A “Send email” action in a campaign that starts when a form is submitted.
formresult
token. You access the submitted values using the form field’s alias (the unique name you gave the field).
- Greets the user by name
- Clearly lists what they submitted
- Uses labels and values for better readability
- Ends with a friendly closing
Using All Submissions (formresults
)
Important: This only works if the email is sent using:
• A “Send email to contact” action directly on a form.
• A “Send email” action in a campaign that starts when a form is submitted.
• A “Send email to contact” action directly on a form.
• A “Send email” action in a campaign that starts when a form is submitted.
formresults
list. Each item in the list (result
in the example below) works like the formresult
token.