I am using an Ajax (POST) request to update the current user profile.
So far I can successfully update the user fields (like fullName
) but I cannot seem to update custom fields.
I have tried adding the custom fields within the fields
array (just like when using an HTML form), but this doesn't seem to work.
Below my code:
$('.js-update-profile').click(function() {
var id = $(this).data('id');
var fields = [];
fields['nickname'] = 'Nickname';
const params = {
CRAFT_CSRF_TOKEN: csrfTokenValue,
userId: player.id,
fields: fields,
};
$.ajax({
url: '/actions/users/save-user',
type: 'POST',
data: params,
headers: {
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
dataType: 'json',
success: function (params) {
console.log(params);
}
});
});
When I excute this code I'm getting a successfull message User saved
, but the custom fields are not updated.
Am I doing something wrong with setting up the params?