1

I have a Countries dropdown menu for signing up that i didn't have before. It used to just be a text field where they can input their own country. It works on the front end sign up form properly, but for the users who don't have the country selected from the new dropdown need to select a country. I have the dropdown on a front end profile form, however when the user "updates" their profile if they don't choose the country it just resets.

For example, I signed in and my country is set to USA and i go to my account to update my password, it resets what's selected on the countries dropdown.

I would like to show the County dropdown for the users who hasn't selected their countries and if the user already selected their country to just show the value they selected.

The code below is the code for the select.

{% set dropdownField = craft.fields.getFieldbyHandle('country') %}
<label for="country">Country</label>
<select class="form-control" id="country" name="fields[country]">
    {% for option in dropdownField.settings.options %}
        <option value="{{ option.value }}" >{{ option.label }}</option>
    {% endfor %}
</select>

1 Answer 1

2

You need to check the currentUser country if it's the same as the option value -> select the option

<option {{ currentUser.country.value == option.value? 'selected' : '' }} value="{{ option.value }}" >{{ option.label }}</option>

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.