I am using saveUser and i am trying to save a value to a user's custom field.
$userModel = new UserModel();
$userModel->mycustomfield = 'test value';
craft()->users->saveUser($userModel);
This is what i have so far.
I am getting this error:
Internal Server Error
Property "Craft\UserModel.mycustomfield" is not defined.
How do i save to a custom user field?
EDIT
Also tried:
$user = craft()->userSession->getUser();
$userModel = new UserModel();
$userModel->id = $user->id;
$userModel->getContent()->setAttributes(array(
'mycustomfield' => 'my field value'
));
craft()->users->saveUser($userModel);
No error, doesnt save either.
EDIT
$userModel->getContent()->mycustomfield = 'my value';
No error, doesnt save.
SOLUTION
$user = craft()->userSession->getUser();
$userModel = new UserModel();
$userModel->id = $user->id;
$userModel->username = $user->username;
$userModel->email = $user->email;
$userModel->password = '';
$userModel->getContent()->mycustomfield = 'my custom value';
$success = craft()->users->saveUser($userModel);
if (!craft()->users->saveUser($userModel))
{
$errors = $userModel->getErrors();
}