You can use data that contacts submit through Mautic forms directly in your emails or landing pages using Twig Templates.

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 or null, 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 or null, 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):
      {% if contact.id is defined %}
          {% set submissionCount = getFormResultsCount(12, contact.id) %}
          <p>You have submitted Form 12 {{ submissionCount }} time(s).</p>
      {% endif %}
      
    • Example (Show the total number of submissions for Form 12 across all contacts):
      {% set totalSubmissions = getFormResultsCount(12) %}
      <p>Form 12 has been submitted a total of {{ totalSubmissions }} times by all contacts.</p>
      

These tokens can be used in emails, landing pages, and other places where Twig Templates are supported.


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

{% set maxRegistrations = 10 %}
{% set totalRegistrations = getFormResultsCount(3) %}

{% if totalRegistrations >= maxRegistrations %}
  <div class="registration-complete-message">
    <h2>Registration Complete</h2>
    <p>Thank you for your interest! Registration for this event is now closed as we have reached the maximum number of participants.</p>
  </div>
{% else %}
{form=3}
{% endif %}

This approach works in landing pages and custom form templates where you can use Twig logic. The form will only be shown if the registration limit has not been reached.


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:

{% if contact.id is defined %}
  {# Get last 3 submissions for this contact #}
  {% set results = getFormResults(12, contact.id, 3) %}
  
  {% if results is not empty %}
    <table class="submission-history">
      <tr>
        <th>Date Submitted</th>
        <th>First Name</th>
        <th>Email Address</th>
        <th>Company Name</th>
      </tr>
      {% for submission in results %}
        <tr>
          <td>{{ submission.dateSubmitted|date('M j, Y g:i a') }}</td>
          <td>{{ submission.firstname }}</td>
          <td>{{ submission.email }}</td>
          <td>{{ submission.company }}</td>
        </tr>
      {% endfor %}
    </table>
  {% else %}
    <p>You haven't submitted this form yet.</p>
  {% endif %}
{% else %}
  <p>Contact information not available.</p>
{% endif %}

This will show:

  1. A table with the submission date, name, email and company
  2. Only the last 3 submissions
  3. A friendly message if no submissions exist

Example: Show Recent Form Submissions from All Contacts

Want to see who’s been submitting Form 12? Here’s how to list the last 5 submissions:

{# Get last 5 submissions from anyone #}
{% set allResults = getFormResults(12, null, 5) %}

{% if allResults is not empty %}
  <div class="recent-submissions">
    <h3>Recent Form Submissions</h3>
    <ul>
      {% for submission in allResults %}
        <li>
          <span class="email">{{ submission.email }}</span>
          <span class="date">on {{ submission.dateSubmitted|date('M j, Y') }}</span>
        </li>
      {% endfor %}
    </ul>
  </div>
{% else %}
  <p>No submissions yet - be the first!</p>
{% endif %}

This will display:

  1. A list of emails from the last 5 submissions
  2. The date they submitted
  3. A friendly message if no one has submitted yet

This lets you show real-world data, like a contact’s submission history, or display recent leads from a form, directly in your emails or landing pages.


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.

To show data from the contact’s latest form submission, use the formresult token. You access the submitted values using the form field’s alias (the unique name you gave the field).

<div class="thank-you-message">
  <p>Hi {{ formresult.firstname }}, thanks for submitting our form!</p>
  
  <p>Here's what we received:</p>
  
  <ul class="submission-details">
    <li>
      <span class="label">First Name:</span>
      <span class="value">{{ formresult.firstname }}</span>
    </li>
    <li>
      <span class="label">Email Address:</span>
      <span class="value">{{ formresult.email }}</span>
    </li>
    <li>
      <span class="label">Your Message:</span>
      <span class="value">{{ formresult.message_field_alias }}</span>
    </li>
  </ul>
  
  <p>We'll be in touch soon!</p>
</div>

This creates a more polished thank you message that:

  1. Greets the user by name
  2. Clearly lists what they submitted
  3. Uses labels and values for better readability
  4. 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.

If you need to show data from older submissions, you can loop through the formresults list. Each item in the list (result in the example below) works like the formresult token.

<p>Your submission history:</p>
<ul>
{% for result in formresults %}
    <li>
        Submitted on {{ result.dateSubmitted|date('Y-m-d H:i') }}:
        Name: {{ result.firstname }} {{ result.lastname }}
        {# Add other fields if needed #}
    </li>
{% else %}
    <li>You haven't submitted this form before.</li>
{% endfor %}
</ul>