1

On the form I'm building, I've got a question with radio buttons. And the answers have custom values. e.g.

Q: What is your favorite color?

  • red (value: 10)
  • blue (value: 20)
  • yellow (value: 30)

On my submissions page, I have the following code

{% for field in submission.fieldMetadata %}
<div class="row">
    <div class="col-xs-3">
        <b>{{ field.label }}/b>:
    </div>
    <div class="col-xs-9">
        {% set fieldValue = attribute(submission, field.handle).value %}
        {% if fieldValue is iterable %}
        <ul>
            {% for value in FieldValue %}
            <li>{{ value }}</li>
            {% endfor %}
        </ul>
        {% else %}
        {{ fieldValue }}
        {% endif %}
    </div>
</div>
{% endfor %}

And this returns:

What is your favorite color: 10

I'm using the values to do some funny math - so it's necessary (but unimportant to the issue at hand).

How to do I get the value "red" to show, instead of the 10?

attribute(submission, field.handle).value - shows the selected option's value (10)
attribute(submission, field.handle).label - shows the question (What is your favorite Color?)
attribute(submission, field.handle).handle - shows the question handle (whatIsYourFavoriteColor)

There should be another function to get the option's value, but I can't find what it is.

1

The code above is correct, but it turns out there was an actual bug in the code if you had a number as the option value.

This affects Freeform 1.5.1 and earlier. The next version (1.5.2) of Freeform will include a fix for this. If anyone needs a patched copy of Freeform before 1.5.2 is available, just contact us via our support form. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.