2

I'm trying to set up a front end user profile that will allow the user to use the multi-select field. When I update from the CP, the changes are reflected on the front end, but this isn't working when trying to update from the front end form.

Is there anything I'm missing?

{% set languageOptionsIds = user.providerLanguages %}

<label for="providerLanguages">What languages do you work with?</label>
{% for option in currentUser.providerLanguages.options %}
    <input type="checkbox" id="providerLanguages" name="fields[providerLanguages][]"
    {% if option.selected in languageOptionsIds %}checked{% endif %} value="{{ option.selected }}">{{ option.label }}
    </input>
{% endfor %}

1 Answer 1

3

I believe that you can get the options directly from the 'currentUser' entry, without referring to 'user' separately (they are likely the same thing in this case anyway):

<label for="providerLanguages">What languages do you work with?</label>
{% for option in currentUser.providerLanguages.options %}
    <input type="checkbox" id="providerLanguages" name="fields[providerLanguages][]"
    {% if option.selected %}checked{% endif %} value="{{ option.value }}">
        {{ option.label }}
    </input>
{% endfor %}

The value is also available as 'option.value' instead of 'option.selected'.

3
  • user is deprecated. currentUser is the way to go.
    – Brad Bell
    Nov 20, 2014 at 23:53
  • @Brad what will the variable be called when viewing or editing someone else's profile? Nov 20, 2014 at 23:59
  • Whatever you set it to? Pretty sure that was the original issue. user used to be global, but people were inadvertently overwriting it in their template code, so we changed the global to currentUser.
    – Brad Bell
    Nov 21, 2014 at 0:04

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.