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 %}
  • Your <select> tags are inside the for loop. Move them outside the loop and you'll be golden! – Ben Fleming Jan 22 '16 at 23:28
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.

  • That didn't seem to do the trick. Was returning a template error. – JackO Jan 22 '16 at 15:54
  • 1
    Code looks legit. What was the error? – Mats Mikkel Rummelhoff Jan 22 '16 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. – Ben Fleming Jan 22 '16 at 23:31

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.