How to update user fields from a custom module form? I need to simply update some user fields from a custom  module form.

I try this but it doesn't works :

/**
 * Submit the register form
 *
 * @param array $form
 * @param FormStateInterface $form_state
 * @return array|RedirectResponse
 */
public function submitForm(array &amp;$form, FormStateInterface $form_state)
{
    // Create a new user
    $values = $form_state-&gt;getValues();

    // User from Drupal\user\Entity\User;
    $user = $this-&gt;ctrUserManager-&gt;getCurrentUser();

    if($user){

        $user-&gt;set('mail', $values['mail']);
        $user-&gt;set('field_last_name', $values['field_lastname']);
        $user-&gt;set('field_first_name', $values['field_first_name']);
        $user-&gt;set('field_civility', [$values['field_civility']]);

        $violations = $user-&gt;validate();

        if (count($violations) === 0) {
            $user-&gt;save();
            \drupal_set_message('Your profile has been updated');
            return $form;
        }
    }

    \drupal_set_message('Error during user profile update', 'error');

    return $form;
}
you are not saving the user correctly, you should call:

$user-&gt;save();


This is an example how to change the username:

$user-&gt;setUsername('new-username');
$user-&gt;save();


Here is another example to add a role to a user:

$user-&gt;addRole('administrator');
$user-&gt;save();


Can you try the following:

/**
 * Submit the register form
 *
 * @param array $form
 * @param FormStateInterface $form_state
 * @return array|RedirectResponse
 */
public function submitForm(array &amp;$form, FormStateInterface $form_state)
{
    // Create a new user
    $values = $form_state-&gt;getValues();

    // User from Drupal\user\Entity\User;
    $user = $this-&gt;ctrUserManager-&gt;getCurrentUser();

    if($user){

        $user-&gt;set('mail', $values['mail']);
        $user-&gt;set('field_last_name', $values['field_lastname']);
        $user-&gt;set('field_first_name', $values['field_first_name']);
        $user-&gt;set('field_civility', [$values['field_civility']]);

        $violations = $user-&gt;validate();

        if (count($violations) === 0) {
            $user-&gt;save();
            drupal_set_message('Your profile has been updated');
        } else {
            drupal_set_message('Error during user profile update', 'error');
        }
    }
}