Freeform Freeform for Craft

User Guides

Line Breaks in Textarea Fields

Textarea fields store data in the database as newlines. When displaying submission data in email notifications or on the front end with a Submissions query, the newlines will not be respected and render as a single clump of text with Twig.

Instructions

To get textarea fields to display correctly with the line breaks, you can use the nl2br Twig filter:

{{ myFieldHandle|nl2br }}
1
{{ submission[field.handle]|nl2br }}
1

Email Notifications

How this may look when displaying submission data in an email notification template when iterating through all fields:




 
 
 





<p>Submitted on: {{ dateCreated|date('l, F j, Y \\a\\t g:ia') }}</p>
<ul>
{% for field in allFields %}
    {% if field.type == "textarea" %}
        {{ field.value|nl2br }}
    {% else %}
        <li>{{ field.label }}: {{ field.valueAsString }}</li>
    {% endif %}
{% endfor %}
</ul>
1
2
3
4
5
6
7
8
9
10

Submissions on Front End

How this may look when displaying submission data for a single submission on the front end (assuming the ID is in 3rd segment) when iterating through all fields:











 
 
 








{% set submissionId = craft.app.request.segment(3) %}
{% set submission = freeform.submissions({id: submissionId}).one() %}

{% if submission %}
    <h3>{{ submission.title }}</h3>
    <table class="table table-striped">
    {% for field in submission %}
        <tr>
            <th>{{ field.label ? field.label : "no-label" }}</th>
            <td>
            {% if field.type == "textarea" %}
                {{ submission[field.handle]|nl2br }}
            {% else %}
                {{ submission[field.handle] }}
            {% endif %}
            </td>
        </tr>
    {% endfor %}
    </table>
{% endif %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20