1

I have this code that will pull the values of a checkbox or radio from the fields in Craft CMS, do be used and selected by a user on a front end form.

<ul>
    {% for checkboxOption in currentUser.fieldHandle.options %}
        {% set checked = false %}

        {% if checkboxOption.selected %}
            {% set checked = true %}
        {% endif %}

        <li>
            <input type="radio" value="{{ checkboxOption.value }}" name="fields[fieldHandle]" {% if checked %} checked="checked" {% endif %}><span>{{ checkboxOption.label }}</span>
        </li>
    {% endfor %}
</ul>

How do I do the same for a dropdown list?

1 Answer 1

0

You'd do something very similar:

<select name="fields[fieldHandle]">

    {% for dropdownOption in currentUser.fieldHandle.options %}
        <option value="{{ dropdownOption.value }}"{% if option.selected %} selected{% endif %}>{{ dropdownOption.label }}</option>
    {% endfor %}

</select>
1
  • Brad, thanks for your help. This worked, and encouraging to know I wasn't far off when I had! Sep 13, 2017 at 9:14

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.