Answers.Body: <p>Close! You should be using <a href="http://buildwithcraft.com/classreference/models/BaseElementModel#setContentFromPost-detail" rel="nofollow noreferrer">setContentFromPost()</a> for this.  See <a href="https://craftcms.stackexchange.com/a/6788/57">here</a> and <a href="https://craftcms.stackexchange.com/questions/4486/what-is-getcontent-the-contentmodel-and-how-do-i-use-it-to-get-and-set-cust">here</a> for more info.</p>
  
  <p>You code would look like:</p>
  
  <pre><code>$user = new UserModel();
  $user-&gt;username  = 'tommy';
  $user-&gt;firstName = 'Tom';
  $user-&gt;lastName  = 'Foolery';
  $user-&gt;email     = 'tom@thefoolery.com';
  $user-&gt;setContentFromPost(array('company' =&gt; 'ACME'));
  
  $success = craft()-&gt;users-&gt;saveUser($user);
  
  if (!$success)
  {
      Craft::log('Couldn’t save the user "'.$user-&gt;username.'"', LogLevel::Error);
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-24T15:07:10.177Z
Answers.Text: Hmmm @brad-bell, that doesn't seem to work... I'm still seeing a blank Company field in the CP. See here: http://bit.ly/1HO5YJO
Answers.UserDisplayName: stursby
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-24T16:59:45.380Z
Answers.Text: Probably a validation error, then?  What does `$user->validate()` return?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T22:54:38.670Z
Answers.LastActivityDate: 2015-07-23T22:54:38.670Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm currently able to add a user with the following code (from <a href="http://buildwithcraft.com/classreference/services/UsersService#saveUser-detail" rel="nofollow">the Docs</a>):</p>
  
  <pre><code>$user = new UserModel();
  $user-&gt;username  = 'tommy';
  $user-&gt;firstName = 'Tom';
  $user-&gt;lastName  = 'Foolery';
  $user-&gt;email     = 'tom@thefoolery.com';
  
  $success = craft()-&gt;users-&gt;saveUser($user);
  
  if (!$success)
  {
      Craft::log('Couldn’t save the user "'.$user-&gt;username.'"', LogLevel::Error);
  }
  </code></pre>
  
  <p>How can I also set the Profile Company name??</p>
  
  <p>I've tried the following with no luck:</p>
  
  <pre><code>$user-&gt;company = 'ACME';
  
  $user-&gt;setContent([ 'fields' =&gt; ['company' =&gt; 'ACME'] ]);
  </code></pre>
  
Tags: <users>
Title: How do I programmatically set a Users company field?
ThreadText: # How do I programmatically set a Users company field?
  
  (Asked by: username_0 on 2015-07-23)
  
  I'm currently able to add a user with the following code (from [the Docs](http://buildwithcraft.com/classreference/services/UsersService#saveUser-detail)):
  
  ```
  $user = new UserModel();
  $user->username  = 'tommy';
  $user->firstName = 'Tom';
  $user->lastName  = 'Foolery';
  $user->email     = 'tom@thefoolery.com';
  
  $success = craft()->users->saveUser($user);
  
  if (!$success)
  {
      Craft::log('Couldn’t save the user "'.$user->username.'"', LogLevel::Error);
  }
  
  ```
  
  How can I also set the Profile Company name??
  
  I've tried the following with no luck:
  
  ```
  $user->company = 'ACME';
  
  $user->setContent([ 'fields' => ['company' => 'ACME'] ]);
  
  ```
  
  **Tags:** users
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-23. Score: 1
  
  Close! You should be using [setContentFromPost()](http://buildwithcraft.com/classreference/models/BaseElementModel#setContentFromPost-detail) for this. See [here](https://craftcms.stackexchange.com/a/6788/57) and [here](https://craftcms.stackexchange.com/questions/4486/what-is-getcontent-the-contentmodel-and-how-do-i-use-it-to-get-and-set-cust) for more info.
  
  You code would look like:
  
  ```
  $user = new UserModel();
  $user->username  = 'tommy';
  $user->firstName = 'Tom';
  $user->lastName  = 'Foolery';
  $user->email     = 'tom@thefoolery.com';
  $user->setContentFromPost(array('company' => 'ACME'));
  
  $success = craft()->users->saveUser($user);
  
  if (!$success)
  {
      Craft::log('Couldn’t save the user "'.$user->username.'"', LogLevel::Error);
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Hmmm @username_1, that doesn't seem to work... I'm still seeing a blank Company field in the CP. See here: http://bit.ly/1HO5YJO  
  > **username_1**: Probably a validation error, then?  What does `$user->validate()` return?  
  
  ---
  
  