<p>What are you trying to output with the last loop in your template?</p>
<p>With <code>craft.contactFormExtensions.submissions</code> you're iterating through <em>submissions</em>, not fields of a single submission. In the e-mail template, you already have access to the current submission through the <code>submission</code> variable, you don't need to go through <code>craft.contactFormExtensions.submissions</code>. Looks like this is intended to show a <a href="https://github.com/hybridinteractive/craft-contact-form-extensions#display-form-submissions-in-your-template-files" rel="nofollow noreferrer">list of submissions</a> (for example, in an admin view of submissions in the frontend).</p>
<blockquote>
<p>Question 1: As you can see the last for loop is formatted somewhat like a JSON array. How can I stop that from happening?</p>
</blockquote>
<p>Since your submission consists of several fields, <code>submission.message</code> is an associative array with field values. You output that directly, triggering the <code>__toString</code> method of the value object. This just prints a JSON string, since it's the only reasonable thing to do in this case.</p>
<blockquote>
<p>Question 2: Since some of the fields are already printed as a separate tag, is it possible to exclude those fields from the last for loop? Because all custom fields are packed into message[custom] the normal twig tags don't seem to work.</p>
</blockquote>
<p>Why are you looping through the fields again if you already output all fields above? Looks like you're trying to loop through a specific field in the submission (<code>Produkte</code>), so you'll need something like <code>submission.message.products</code> (replace the last part with the name of the field in your contact form template).</p>
<p>If you want to display some hardcoded fields at the top and then display all other fields in a list, you can use the <a href="https://twig.symfony.com/doc/3.x/filters/filter.html" rel="nofollow noreferrer"><code>filter</code> filter</a> to exclude some fields from the loop:</p>
<pre class="lang-twig prettyprint-override"><code>{% set excludedFields = ['firstName', 'shippingAddress', 'zip'] %}
{% for field in submission.message|filter((_, field) =&gt; field not in excludedFields) %}
    {{ field }}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2023-01-24T11:00:06.913Z
Fantastic. Besides the hardcoded fields I have a loop which creates non hardcoded select fields inside the contact form. So I cant just hardcode everything. I'll try it out.
KSPR
CC BY-SA 4.0
2023-01-24T12:32:18.517Z
@KSPR Yeah, in this case the last code example is probably what you're looking for. By the way, you can also invert the logic if you want to specify an include list instead of an exclude list for the fields to display. Just use `in` instead of `not in` in this case, then you only need to specify the fields you want to display. Whichever is easier.
MoritzLost
CC BY-SA 4.0
2023-01-23T15:32:02.083Z
2023-01-23T15:32:02.083Z
MoritzLost
<p>I use <a href="https://github.com/craftcms/contact-form" rel="nofollow noreferrer">contact-form plugin</a> together with <a href="https://github.com/hybridinteractive/craft-contact-form-extensions" rel="nofollow noreferrer">contact-form-extensions</a> to create a human-readable E-Mail.</p>
<p>I've gotten so far:</p>
<pre><code>------ &lt;br&gt;
&lt;p&gt;
{{ submission.fromName }} &lt;br&gt;
{{ submission.message['firstName'] }} {{ submission.message['lastName'] }} &lt;br&gt;
{{ submission.message['shippingaddress'] }} &lt;br&gt;
{{ submission.message['zip'] }}{{ submission.message['city'] }}
&lt;/p&gt;
------ &lt;br&gt;
&lt;p&gt;
{% for submission in craft.contactFormExtensions.submissions %}
   {% if loop.first %}
      Bestelldatum: {{ submission.dateCreated|date('d-m-Y H:i') }}&lt;br&gt;
   {% endif %}
{% endfor %}
E-Mail: &lt;a href=&quot;mailto:{{ submission.fromEmail }}&quot;&gt;{{ submission.fromEmail }}&lt;/a&gt; &lt;br&gt;
Telefon: &lt;a href=&quot;tel:{{ submission.message['tel'] }}&quot;&gt;{{ submission.message['tel'] }}&lt;/a&gt; &lt;br&gt;
Nachricht: {{ submission.message['body'] }}&lt;/p&gt;
&lt;/p&gt;
------ &lt;br&gt;
&lt;p&gt;Produkte:&lt;/p&gt;

{% for submission in craft.contactFormExtensions.submissions %}
   {% if loop.first %}
      {{ submission.message }}
   {% endif %}
{% endfor %}
</code></pre>
<p>This works and results in this E-Mail:</p>
<p><a href="https://i.sstatic.net/h6Dju.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/h6Dju.png" alt="enter image description here" /></a></p>
<p>Question 1: As you can see the last for loop is formatted somewhat like a JSON array. How can I stop that from happening?</p>
<p>Question 2: Since some of the fields are already printed as a separate tag, is it possible to exclude those fields from the last for loop? Because all custom fields are packed into <code>message[custom]</code> the normal twig tags don't seem to work.</p>

<plugin-contactform><plugin-contactformextensions>
contact-form human readable E-Mail template
# contact-form human readable E-Mail template

(Asked by: username_0 on 2023-01-23)

I use contact-form plugin together with contact-form-extensions to create a human-readable E-Mail.
I've gotten so far:
------ 

{{ submission.fromName }} 
{{ submission.message['firstName'] }} {{ submission.message['lastName'] }} 
{{ submission.message['shippingaddress'] }} 
{{ submission.message['zip'] }}{{ submission.message['city'] }}

------ 

{% for submission in craft.contactFormExtensions.submissions %}
   {% if loop.first %}
      Bestelldatum: {{ submission.dateCreated|date('d-m-Y H:i') }}
   {% endif %}
{% endfor %}
E-Mail: {{ submission.fromEmail }} 
Telefon: {{ submission.message['tel'] }} 
Nachricht: {{ submission.message['body'] }}

------ 
Produkte:

{% for submission in craft.contactFormExtensions.submissions %}
   {% if loop.first %}
      {{ submission.message }}
   {% endif %}
{% endfor %}

This works and results in this E-Mail:

Question 1: As you can see the last for loop is formatted somewhat like a JSON array. How can I stop that from happening?
Question 2: Since some of the fields are already printed as a separate tag, is it possible to exclude those fields from the last for loop? Because all custom fields are packed into message[custom] the normal twig tags don't seem to work.

**Tags:** plugin-contactform, plugin-contactformextensions

---

## 1 answers

### Answer by username_1 on 2023-01-23. Score: 2 | Accepted answer

What are you trying to output with the last loop in your template?
With craft.contactFormExtensions.submissions you're iterating through submissions, not fields of a single submission. In the e-mail template, you already have access to the current submission through the submission variable, you don't need to go through craft.contactFormExtensions.submissions. Looks like this is intended to show a list of submissions (for example, in an admin view of submissions in the frontend).

Question 1: As you can see the last for loop is formatted somewhat like a JSON array. How can I stop that from happening?

Since your submission consists of several fields, submission.message is an associative array with field values. You output that directly, triggering the __toString method of the value object. This just prints a JSON string, since it's the only reasonable thing to do in this case.

Question 2: Since some of the fields are already printed as a separate tag, is it possible to exclude those fields from the last for loop? Because all custom fields are packed into message[custom] the normal twig tags don't seem to work.

Why are you looping through the fields again if you already output all fields above? Looks like you're trying to loop through a specific field in the submission (Produkte), so you'll need something like submission.message.products (replace the last part with the name of the field in your contact form template).
If you want to display some hardcoded fields at the top and then display all other fields in a list, you can use the filter filter to exclude some fields from the loop:
{% set excludedFields = ['firstName', 'shippingAddress', 'zip'] %}
{% for field in submission.message|filter((_, field) => field not in excludedFields) %}
    {{ field }}
{% endfor %}

> **Comments:**
> **username_0**: Fantastic. Besides the hardcoded fields I have a loop which creates non hardcoded select fields inside the contact form. So I cant just hardcode everything. I'll try it out.  
> **username_1**: @KSPR Yeah, in this case the last code example is probably what you're looking for. By the way, you can also invert the logic if you want to specify an include list instead of an exclude list for the fields to display. Just use `in` instead of `not in` in this case, then you only need to specify the fields you want to display. Whichever is easier.  

---

