hybridinteractive / craft-contact-form-extensions

Adds extensions to the Craft CMS contact form plugin.
MIT License
43 stars 36 forks source link

E-Mail Template all submission are printed in each mail #169

Closed kaspar-allenbach closed 1 year ago

kaspar-allenbach commented 1 year ago

I try to create a decent human readable template.

<p>{{ submission.fromName }}</p>
<p>{{ submission.fromEmail }}</p>

{% for submission in craft.contactFormExtensions.submissions %}
    {{ submission.dateCreated|date('d-m-Y H:i') }}
    {{ submission.message }}
{% endfor %}

Craft CMS: 3.7.63.1 php 8.1.1

How do I print a field within the message field:

If I have:

<input type="text" id="message" name="message[firstName]" value="" autocomplete="firstName" required="true">

in the E-Mail

{{ submission.message[firstName] }}

is not working.

Variable "firstName" does not exist.

Any idea about E-Mail Submission templating?

rosskenney commented 1 year ago

Should be {{ submission.message.firstName }} But also something like this should help if you want to print out the label and value.

{% for key, value in submission.message %}
    {% if value is iterable %}
        {% for item in value %}
            <p>{{ key|ucfirst }}: {{ item|nl2br }}</p>
        {% endfor %}
    {% else %}
        <p>{{ key|ucfirst }}: {{ value|nl2br }}</p>
    {% endif %}
{% endfor %}