This document is for an older version of
Freeform
. View latest version →freeform.submissions function
The freeform.submissions template function fetches a list of submissions based on some or no criteria.
Parameters
form
#- Handle of the form, e.g.
"composerForm"
, or an array of handles:["composerForm", "clientSurvey"]
. - Use
"not composerForm"
to select all submissions EXCEPT the ones for Composer Form form.
- Handle of the form, e.g.
formId
#- An ID of the form, or array of ID's, e.g.
[1, 2, 3]
. - If you want to select all form submissions EXCEPT the form with an ID of 1, use
"not 1"
.
- An ID of the form, or array of ID's, e.g.
limit
#- Supply an
int
to limit the amount of submissions returned.
- Supply an
order
#- Use any field handle to order by that value and include the
ASC
orDESC
parameter in the string, e.g.order: "firstName ASC"
.
- Use any field handle to order by that value and include the
status
#- Specify status to fetch submissions with a certain status.
status: "open"
if you have a status with a handleopen
.
Usage in Templates
Display a simple list of submissions:
{% set submissions = craft.freeform.submissions({
order: "firstName ASC, lastName DESC",
status: ["pending", "closed"],
}) %}
{% for submission in submissions %}
<div>
{{ submission.title }} - {{ submission.firstName }}
</div>
{% endfor %}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Print out all submissions and check if fields exist for the submitted form, before printing them out:
{% set submissions = craft.freeform.submissions({
order: "firstName ASC, lastName DESC",
status: ["pending", "closed"],
}) %}
{% for submission in submissions %}
<div>
<div>{{ submission.title }} - {{ submission.form.name }}</div>
{% if submission.firstName is not null %}
{{ submission.firstName.label }}: {{ submission.firstName }}<br>
{% endif %}
{% if submission.lastName is not null %}
{{ submission.lastName.label }}: {{ submission.lastName }}<br>
{% endif %}
</div>
{% endfor %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
To paginate submissions, use Craft's Pagination. Here's an example:
{% paginate craft.freeform.submissions({limit: 5}) as pageInfo, submissions %}
{% for submission in submissions %}
<div>
<div>{{ submission.title }} - {{ submission.form.name }}</div>
</div>
{% endfor %}
{% if pageInfo.prevUrl %}
<a href="{{ pageInfo.prevUrl }}">Previous Page</a>
{% endif %}
{% if pageInfo.nextUrl %}
<a href="{{ pageInfo.nextUrl }}">Next Page</a>
{% endif %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
To display a single submission (see Submission object for more info):
{% set submissionId = craft.request.segment(5) %}
{% set submission = craft.freeform.submissions({id: submissionId}).first() %}
{% if submission %}
{% set form = submission.form %}
<h3>{{ form.name }} - {{ submission.title }}</h3>
<table class="table table-striped">
{% for field in submission.fieldMetadata %}
<tr>
<th style="width: 20%;">{{ field.label ? field.label : "no-label" }}</th>
<td>
{% set fieldValue = attribute(submission, field.handle).value %}
{% if fieldValue is iterable %}
<ul>
{% for value in fieldValue %}
<li>{{ value }}</li>
{% endfor %}
</ul>
{% else %}
{{ fieldValue }}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<div class="alert alert-danger">
<p class="lead">
Sorry, no submission was found.
</p>
</div>
{% 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
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
The following is an example that shows how to render uploaded Assets in your form submissions:
{% 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 assetId = attribute(submission, field.handle) %}
{% set asset = craft.assets.id(assetId).first() %}
{% if asset %}
{% if asset.kind == "image" %}
<img src="{{ asset.url }}" />
{% else %}
<a href="{{ asset.url }}">{{ asset.filename }}</a>
{% endif %}
{% 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
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