This document is for an older version of

Freeform

.

View latest version →

Submission

Properties

  • id #
    • The event's unique ID, which is also the element ID.
  • incrementalId #
    • The unique incremental ID of the submission (not element ID).
  • title #
    • The submission's title.
  • dateCreated #
    • The DateTime object of when the submission was submitted.
  • statusModel #
    • statusModel.name - the submission's status name.
    • statusModel.handle - the submission's status handle.
    • statusModel.color - the submission's status color.
  • formId #
    • Related form's ID.
  • form #
    • The Freeform_FormModel.
  • ip #
    • The IP address of the submitter, if collection of IP addresses is enabled
  • token #
    • The token generated for the submission.
    • A common use-case for tokens would be when you want to have a more secure URL for accessing and displaying submission data, or allowing users to delete their own submission and not requiring any login, etc.
  • fieldMetadata #
    • A list containing all fields who store values (doesn't include HTML fields, submit fields, mailing-list fields).
    • Each of the objects is a Field object, and contains the submitted value.
    • You can access all of the field properties for each field specific to the current submissions related Form.
  • You can access any field in the submission's form by the field's handle:
    • If you have a field with a handle firstName, you can access its value by calling:
      • {{ submission.firstName }} or
      • Get its label {{ submission.firstName.label }}
        • Any other property such as placeholder, options, defaultValue, etc is also available.
        • Some properties are field type specific. For example, you wouldn't be able to get rows from a select field, or options from a textarea field.

Usage in Templates

Below is a basic example of how to display a list of submissions for a given form:

{% set formHandle = 'yourFormHandle' %}
{% set submissions = craft.freeform.submissions({
  form: formHandle,
}) %}

<h3>Submissions for {{ form.name }}</h3>

{% if submissions is empty %}
  <div>There are no submissions</div>
{% else %}
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Title</th>
        {% for field in (submissions|first).fieldMetadata %}
          <th>{{ field.label }}</th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
    {% for submission in submissions %}
      <tr>
        <td>{{ submission.id }}</td>
        <td>
          <a href="{{ siteUrl }}freeform_demo/bootstrap/{{ form.handle }}/submissions/{{ submission.id }}">
            {{ submission.title }}
          </a>
        </td>
        {% for field in submission.fieldMetadata %}
          <td>
            {% if field.type == "file" %}
              {% set assetIds = attribute(submission, field.handle).value %}
              {% if assetIds %}
                {% for assetId in assetIds %}
                  {% set asset = craft.assets.id(assetId).one() %}
                  {% if asset %}
                    {% if asset.kind == "image" %}
                      <img src="{{ asset.url }}" class="img-responsive" />
                    {% else %}
                      <a href="{{ asset.url }}">{{ asset.filename }}</a>
                    {% endif %}
                  {% endif %}
                {% endfor %}
              {% endif %}
            {% else %}
              {{ attribute(submission, field.handle) }}
            {% endif %}
          </td>
        {% endfor %}
      </tr>
    {% endfor %}
    </tbody>
  </table>
{% endif %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

Below is a basic example of how to display a single view submission, assuming the submission ID is in the third segment:

{% set submission = craft.freeform.submissions({
  form: 'youFormHandle',
  id: craft.app.request.segment(3),
}).one() %}

<h3>
  {{ form.name }} - {{ submission.title }}
  ({{ submission.statusModel.name }})
</h3>

<table class="table table-striped">
{% for field in submission.fieldMetadata %}
  <tr>
    <th style="width: 20%;">{{ field.label }}</th>
    <td>
    {% if field.type == "file" %}
      {% set assetId = attribute(submission, field.handle) %}
      {% set asset = craft.assets.id(assetId).one() %}
      {% if asset %}
        <img src="{{ asset.url }}" />
      {% endif %}
    {% elseif field.type == "dynamic_recipients" %}
      {{ field.value }}
    {% else %}
      {{ attribute(submission, field.handle) }}
    {% endif %}
    </td>
  </tr>
{% endfor %}
</table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30