Answers.Body: <p>To Create a user do</p>
  
  
  
  <pre><code>$request = Craft::$app-&gt;getRequest();
  $user = new User();
  $user-&gt;username         = $request-&gt;getBodyParam('username');
  $user-&gt;email            = $request-&gt;getBodyParam('email');
  $user-&gt;newPassword      = $request-&gt;getBodyParam('password');
  $user-&gt;firstName        = $request-&gt;getBodyParam('firstName');
  $user-&gt;lastName         = $request-&gt;getBodyParam('firstName');
  $user-&gt;setScenario(User::SCENARIO_REGISTRATION);
  Craft::$app-&gt;getElements()-&gt;saveElement($user);
  </code></pre>
  
  <p>To update a user</p>
  
  <pre class="lang-php prettyprint-override"><code>$request            = Craft::$app-&gt;getRequest();
  $user-&gt;username     = $request-&gt;getBodyParam('username');
  $user-&gt;email        = $request-&gt;getBodyParam('email');
  $user-&gt;newPassword  = $request-&gt;getBodyParam('password');
  $user-&gt;firstName    = $request-&gt;getBodyParam('firstName');
  $user-&gt;lastName     = $request-&gt;getBodyParam('firstName');
  $user-&gt;setScenario(User::SCENARIO_LIVE);
  Craft::$app-&gt;getElements()-&gt;saveElement($user);
  </code></pre>
  
  <p>So it's basically the same except the scenario</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T11:48:56.560Z
Answers.Text: What if the fields are custom?
Answers.UserDisplayName: Billy Sengsey
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T11:55:50.787Z
Answers.Text: You mean how to populate fields in the field layout?
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-03T13:11:14.933Z
Answers.Text: @BillySengsey or @ anyone who arrives here through Google... custom fields are as simple as using the field handle: `$user->customField = 'whatever';` Matrix fields will be a different challenge however...
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-25T18:01:52.373Z
Answers.LastActivityDate: 2018-09-25T18:01:52.373Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have 2 forms on my site, one that registers for the WHOLE site and one that registers for just the downloads on the site. I wrote this custom function to change the user group if the email existed. So basically what i'm going for here is if someone signed up for ONLY the downloads and wanted to signup for the whole site to let them use their email they used to sign up originally.</p>
  
  <p>So basically they fill out the sign up form use the same email etc.</p>
  
  <p>Currently the code i have isn't working properly. It changes the user group and allows the user to sign up IF they already signed up, however it won't update the rest of my user fields on the form. If a new user comes to the site and tries to sign up for the whole site the signup form doesn't work, it doesn't save the user, just redirects to the login page.</p>
  
  <p><a href="https://i.sstatic.net/JNiPB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JNiPB.png" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-25T17:08:13.993Z
Comments.Text: You need to save/create the user in both scenarios if you want to update fields. So to keep it simple (please leave all not necessary information) all your question is about "how to create/update a user"? If I remember correctly you asked this question already a few days ago
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-25T17:35:56.773Z
Comments.Text: I asked a similar question 13 days ago, i hadn't started developing the functionality yet. How do i go about doing it in both scenarios ?
Comments.UserDisplayName: Kevin Love
Tags: <plugin-development><craft3><custom>
Title: Updating craft user fields from plugin
ThreadText: # Updating craft user fields from plugin
  
  (Asked by: username_0 on 2018-09-25)
  
  I have 2 forms on my site, one that registers for the WHOLE site and one that registers for just the downloads on the site. I wrote this custom function to change the user group if the email existed. So basically what i'm going for here is if someone signed up for ONLY the downloads and wanted to signup for the whole site to let them use their email they used to sign up originally.
  
  So basically they fill out the sign up form use the same email etc.
  
  Currently the code i have isn't working properly. It changes the user group and allows the user to sign up IF they already signed up, however it won't update the rest of my user fields on the form. If a new user comes to the site and tries to sign up for the whole site the signup form doesn't work, it doesn't save the user, just redirects to the login page.
  
  [![enter image description here](https://i.sstatic.net/JNiPB.png)](https://i.sstatic.net/JNiPB.png)
  
  **Tags:** plugin-development, craft3, custom
  
  > **Comments:**
  > **username_1**: You need to save/create the user in both scenarios if you want to update fields. So to keep it simple (please leave all not necessary information) all your question is about "how to create/update a user"? If I remember correctly you asked this question already a few days ago  
  > **username_0**: I asked a similar question 13 days ago, i hadn't started developing the functionality yet. How do i go about doing it in both scenarios ?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-25. Score: 1
  
  To Create a user do
  
  ```
  $request = Craft::$app->getRequest();
  $user = new User();
  $user->username         = $request->getBodyParam('username');
  $user->email            = $request->getBodyParam('email');
  $user->newPassword      = $request->getBodyParam('password');
  $user->firstName        = $request->getBodyParam('firstName');
  $user->lastName         = $request->getBodyParam('firstName');
  $user->setScenario(User::SCENARIO_REGISTRATION);
  Craft::$app->getElements()->saveElement($user);
  
  ```
  
  To update a user
  
  ```php
  $request            = Craft::$app->getRequest();
  $user->username     = $request->getBodyParam('username');
  $user->email        = $request->getBodyParam('email');
  $user->newPassword  = $request->getBodyParam('password');
  $user->firstName    = $request->getBodyParam('firstName');
  $user->lastName     = $request->getBodyParam('firstName');
  $user->setScenario(User::SCENARIO_LIVE);
  Craft::$app->getElements()->saveElement($user);
  
  ```
  
  So it's basically the same except the scenario
  
  > **Comments:**
  > **username_2**: What if the fields are custom?  
  > **username_1**: You mean how to populate fields in the field layout?  
  > **username_3**: @username_2 or @ anyone who arrives here through Google... custom fields are as simple as using the field handle: `$user->customField = 'whatever';` Matrix fields will be a different challenge however...  
  
  ---
  
  