2

I have added a form to my front-end to edit the user's first and last name. Editing all the other fields is not a problem but when I try to edit the first or last name it doesn't work.

I think I might need to change name="fields[firstName]" to something else, but I don't know to what I should change it to.

<form method="post" id="loginForm" accept-charset="UTF-8" enctype="multipart/form-data">
    {{ getCsrfInput() }}
    <h1 class="login-text">{{'Profiel bewerken'|upper}}</h1>
    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="profile">
    <input type="hidden" name="userId" value="{{ currentUser.id }}">  

    <label for="voornaam">{{"voornaam"|title}}</label>
    <input type="text" id="voornaam" name="fields[firstName]"
    {% if currentUser.firstName %}value="{{ currentUser.firstName }}"{% endif %}>

    <label for="achternaam">{{"achternaam"|title}}</label>
    <input type="text" id="achternaam" name="fields[lastName]"
    {% if currentUser.lastName %}value="{{ currentUser.lastName }}"{% endif %}>

    <label for="woonplaats">{{"woonplaats"|title}}</label>
    <input type="text" id="woonplaats" name="fields[woonplaats]"
    {% if currentUser.woonplaats %}value="{{ currentUser.woonplaats }}"{% endif %}>

    <label for="postcode">{{"postcode"|title}}</label>
    <input type="text" id="postcode" name="fields[postcode]"
    {% if currentUser.postcode %}value="{{ currentUser.postcode }}"{% endif %}>

    <label for="adres">{{"adres"|title}}</label>
    <input type="text" id="adres" name="fields[adres]"
    {% if currentUser.adres %}value="{{ currentUser.adres }}"{% endif %}>

    {# Check to see if the user has a photo  #}
    <label>Profielfoto</label><br />
    {% if currentUser.photoUrl %}
        <img src="{{ currentUser.photoUrl }}" alt="{{ currentUser.title }}"><br />
        <input type="file" name="userPhoto" value="Change Photo">
    {% else %}
        {# If no photo exists, give the option to upload a new one #}
        <input type="file" name="userPhoto" value="Upload">
    {% endif %}

    {# <input type="file" name="userPhoto" value="{{ (currentUser.photoUrl ? 'Change Photo' : 'Upload') }}"> #}

    <br /><button type="submit">Opslaan</button>

    <div class="clear"></div>
</form>
3

A User's first and last name fields don't need the fields[] prefix as they aren't custom fields added to the user field group.

So using the following should work:

<label for="voornaam">{{"voornaam"|title}}</label>
<input type="text" id="voornaam" name="firstName"
{% if currentUser.firstName %}value="{{ currentUser.firstName }}"{% endif %}>

<label for="achternaam">{{"achternaam"|title}}</label>
<input type="text" id="achternaam" name="lastName"
{% if currentUser.lastName %}value="{{ currentUser.lastName }}"{% endif %}>

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.