amforms
amforms copied to clipboard
Translate more fields in email notification/confirmation template
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).
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
Hm for entries I do have a limit of one entry selection. So for multiple, this should be improved a bit more :)