Matching form value in sent email

Hi, I have a quick question regarding twig and forms: Let’s say my yaml is as below for a frontend form:

            name: test
            type: radio
                foo1: bar1
                foo2: bar2
                foo3: bar3
                foo4: bar4

In the mail sent with data.html.twig, I can retrieve the ‘foo’ selected with {{ string(form.value(test)|e) }} but I would like to display instead the matching value of ‘bar’.
Any idea?

This is an standard HTML Form behavior. Grav renders your example to:

<select name="test">
<option value="foo1">bar1</option>
<option value="foo2">bar2</option>
<option value="foo3">bar3</option>
<option value="foo4">bar4</option>

After the user hits the submit button a post / get happens and send the key | value pair to the server. In your case the key is “test” and the value is “foo1” / “foo2” / “foo3” or “foo4”. Depends on the option the user selected. Unfortunately this is all the data you could grap in the mail. Which I would try is to use hidden fields for sending the display values with the keys of your select list.

  type: hidden
  default: bar1
  type: hidden
  default: bar2
  type: hidden
  default: bar2

Then you could resolve the display value over Twig like so: (untested)


Thanks for your help! It might indeed be a solution, but I finally found, after hours of research how to achieve it. Leaving the code here in case it might help:

  {% for field in form.fields %}
       {% block field %}

         <p>{% block field_label %}
            <strong>{{ field.label }}</strong>
           {% endblock %}:
              	{% block field_value %}
                	{% if field.type == 'radio' %}
                                  {% set result = string(form.value(|e) %}
                                  {{ field.options[result] }}
                	{% else %}
                	 {{ string(form.value(|e)|nl2br }}
                	{% endif %}

              		{% endblock %}</p>

          {% endblock %}
  {% endfor %}