13

This question is similar to this post, but more of the next logical step.

I have added custom fields to my user profiles, but would like these attributes to be part of the registration page.

For example I'd like the user to specify their address on sign up, but I haven't found a way to reference this field correctly in the page.

Something like:

<h3><label for="Address">Address</label></h3>
<input id="Address" type="text" name="Address"
    {%- if account is defined %} value="{{ account.Address}}"{% endif -%}>

{% if account is defined %}
    {{ errorList(account.getErrors('Address')) }}
{% endif %}

This doesn't work because account.Address doesn't seem to be the correct way to access custom user fields on registration, and the only way I currently know how to access this field would be through currentUser.Address, but that relies on the account all ready being created.

Does anyone know how to access these fields to save during registration, or am I going to have to create the account first then have a second page that allows the user to set these fields?

1 Answer 1

20

You need to change your input tag from:

<input id="Address" type="text" name="Address"
{%- if account is defined %} value="{{ account.Address}}"{% endif -%}>

To:

<input id="Address" type="text" name="fields[Address]"
{%- if account is defined %} value="{{ account.Address}}"{% endif -%}>

All custom fields input types should have a name prefixed with fields[].

2
  • No worries... care to mark it as the answer?
    – Brad Bell
    Commented Oct 23, 2014 at 23:33
  • A bit on the side, but for future reference: If the user field is of type Checkboxes you will need to add [] to the name to support multiple selections. Ex. <input name="fields[options][]" type="checkbox" value="enableBetaFeatures" {{ currentUser.options.contains('enableBetaFeatures') ? "checked" : "" }} />
    – PWL
    Commented Feb 3, 2022 at 13:18

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.