Submission object
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.
status
#- The submission's status color.
- To get the status name/handle, you'll need to access the
statusModel
model:statusModel.name
- the submission's status name.statusModel.handle
- the submission's status handle.
formId
#- Related form's ID.
form
#- The Freeform_FormModel.
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 aselect
field, oroptions
from atextarea
field.
- Any other property such as
- If you have a field with a handle
Usage in Templates
Basic List
Below is a basic example of how to display a list of submissions for a given form:
{% set formHandle = 'yourFormHandle' %}
{% set submissions = 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) %}
<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 %}
<td>
{% if field.type == "file" %}
{% set assetIds = 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 %}
{{ submission[field.handle] }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
Basic Single
Below is a basic example of how to display a single view submission, assuming the submission ID is in the third segment:
{% set submission = freeform.submissions({
form: 'yourFormHandle',
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 %}
<tr>
<th style="width: 20%;">{{ field.label }}</th>
<td>
{% if field.type == "file" %}
{% set assetId = 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 %}
{{ submission[field.handle] }}
{% endif %}
</td>
</tr>
{% endfor %}
</table>