am-impact / amforms

Forms plugin for Craft
Other
120 stars 21 forks source link

Translate more fields in email notification/confirmation template #125

Open bertoost opened 7 years ago

bertoost commented 7 years ago

I discovered not all field types are supported by the email template correctly. For example; when you have an Entries field, the "value" will not be the ID, but some criteria model. And when having radio buttons or such, you want to show the label and not the actual value (which can be different)

To solve this;

{%- set value = attribute(submission, field.handle) -%}
...
{% switch field.type %}
    ...
    {% case 'RadioButtons' %}
        {{ value.label|t }}
    {% case 'Entries' %}
        {% set relatedEntryId = value.id|first -%}
        {% set relatedEntry = craft.entries.id(relatedEntryId).first -%}
        {{ relatedEntry.title }}
    ...
{% endswitch %}

Probably there are more missing field types, like Matrix blocks. But I didn't have them yet (if I have time, I will figure them out).

bertoost commented 7 years ago

Therefor I also check if the value is empty. Because sometimes a form field is not required and you don't want to have them appearing empty in your emails

bertoost commented 7 years ago

Hm for entries I do have a limit of one entry selection. So for multiple, this should be improved a bit more :)