0

I want users to be able select their own name prefix/title (Mr, Mrs, Dr. etc) as part of front end form that allows them to update their user details.

I have created a custom dropdown field and populated this with the titles that users can select. However, I'm having trouble displaying the dropdown on the front end form that allows users to select one option.

Any guidance on how I would go about achieving this would be helpful!


EDIT

This is what I had initially. However, this just prints each option as a separate select?

{% set dropdownField = craft.fields.getFieldbyHandle('honorific') %}

{% for option in dropdownField.settings.options %}
    <select id="honorific" name="honorific">
        <option value="{{ option.value }}">{{ option.label }}</option>
    </select>
{% endfor %}
1
  • Your <select> tags are inside the for loop. Move them outside the loop and you'll be golden! Commented Jan 22, 2016 at 23:28

1 Answer 1

3

Just to make sure I am on the same page, you have a select field within the control panel that is populated with the prefix/title(s)?

If that's the case, within your registration form, you could do something like this. Not tested, but should be close...

{% set options = craft.fields.getFieldByHandle('yourFieldHandle').getFieldType.options %}

{% if options|length %}
    <label for="prefix">Prefix</label>
    <select id="prefix" name="fields[prefix]">
        {% for option in options %}
            <option value="{{ option.value }}">{{ option.label }}</option>
        {% endfor %}
    </select>
{% endif %}

EDIT

Good catch by @Benjammin'. You will need the options part to actually access the values. I've updated my answer, give it another try.

3
  • That didn't seem to do the trick. Was returning a template error.
    – JackO
    Commented Jan 22, 2016 at 15:54
  • 1
    Code looks legit. What was the error? Commented Jan 22, 2016 at 16:20
  • 2
    The options variable is getting the FieldModel, not the list of options. To get the list of options you need to access .settings.options on the field model. Commented Jan 22, 2016 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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