Does anyone know if there is a block on updating users form an action?

Trying to update a users custom field in craft 3 via plugin in the admin. The admin template calls an ajax call to the action when a drop-down is changed.

This works ok in the base of the plugin, but not in an action.

    public function actionUpdateuser()
        // Update user data
        $userId = 67852;
        $user = Craft::$app->users->getUserById($userId);
        $user->setFieldValue('userCompanyName', 'New Name 2'); 
        $result = Craft::$app->elements->saveElement($user);

        return $result;

The action fires ok and can return other things just does not update the user.

  • What type of field is your userCompanyName? – Oli Feb 9 at 10:16
  • It's just a plain text field. It works ok if I add the same code to the Custom.php which is the main plugin file. – Green17 Feb 9 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.