Freeform Documentation

Learn the basics, and get to know Freeform inside and out.

Freeform 1.x Docs

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 #
  • 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 %}

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>