Answers.Body: <blockquote>
    <p>Can I somehow solve this?</p>
  </blockquote>
  
  <p>Yes by creating a custom Controller. Because the default <code>UsersController</code> does the following</p>
  
  <pre><code>// Don't validate required custom fields if it's public registration
  if (!$thisIsPublicRegistration) {
      $user-&gt;setScenario(Element::SCENARIO_LIVE);
  }
  </code></pre>
  
  <p>without <code>SCENARIO_LIVE</code> custom fields won't be stored</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T13:04:37.933Z
Answers.Text: That's not the issue, my custom fields do get stored. The issue is that 20% of the time the user isn't getting assigned to the group and I get a 403 error. The other 80% of the time it works perfectly
Answers.UserDisplayName: Branko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T13:06:01.120Z
Answers.Text: Could you eventually tell me what the error message is exactly? You can take a look into your Yii dev Toolbar, in your logs or in your browser network tab. Maybe the user doesn't have the permission to assign to the group
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T13:14:11.663Z
Answers.Text: thanks for the quick reply, I took a look at the toolbar and I see the following error: "This action can only be done by an administrator". I am the admin and have full permissions. Also, do you know why this only happens 20% of the time?
Answers.UserDisplayName: Branko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T13:16:31.200Z
Answers.Text: When you are dealing with registrations and storing users you'll likely get logged out and in as the other user. So chances are high you have a different account than you expect to have
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T13:21:30.713Z
Answers.Text: I don't think that's what's happening because I have full access to the dashboard at all times even after creating the new user(s). I can't be logged in as the new user because the new user account is still set to pending. Thanks for your help though
Answers.UserDisplayName: Branko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T11:49:39.943Z
Answers.LastActivityDate: 2018-06-19T11:49:39.943Z
Answers.UserDisplayName: Robin Schambach
Answers.Body: <p>I found out that this has been an issue since December 2017: <a href="http://github.com/craftcms/cms/issues/2194" rel="nofollow noreferrer">github.com/craftcms/cms/issues/2194</a> .I hope they fix it soon. For now I'll go back to craft 2</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T13:42:39.137Z
Answers.LastActivityDate: 2018-06-19T13:42:39.137Z
Answers.UserDisplayName: Branko
Body: <p>I am experiencing a very weird issue. I have a simple user registration form:</p>
  
  <pre><code>&lt;form method="post" action="" accept-charset="UTF-8" id="addTeacherForm"&gt;
      {{ csrfInput() }}
  
      &lt;input type="hidden" name="action" value="users/save-user" /&gt;
      &lt;input type="hidden" name="fields[schoolId][]" value="{{ currentUser.id }}" /&gt;
      &lt;input type="hidden" name="groups[]" value="3" /&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label for="username"&gt;Username &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
          &lt;input id="username" type="text" class="form-control" name="username" required /&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
           &lt;label for="email"&gt;E-mailadres &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
          &lt;input id="email" type="text" class="form-control" name="email" required /&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label for="password"&gt;Password &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
          &lt;input id="password" type="password" class="form-control" name="password" required /&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;button type="submit" class="btn btn-primary btn-submit float-right"&gt;
              Docent toevoegen
          &lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have an event listener for the form submit and I submit the form using ajax. This code works perfectly most of the time, but sometimes (like 20% of the time) I get a 403 forbidden error in the console. When I comment out the hidden groups[] input field I don't experience this issue at all. </p>
  
  <p>It is also worth noting that even though I get this error the user is created but doesn't get added to the group.</p>
  
  <p>I'm starting to think this is a craft 3 issue. </p>
  
  <p>Can I somehow solve this?</p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-26T04:16:47.603Z
Comments.Text: As noted in your answer below, this is related to a longstanding bug report. Closing as a "bug report".
Comments.UserDisplayName: Lindsey D
Tags: <ajax><registration>
Title: Ajax User registration sometimes forbidden 403 error
ThreadText: # Ajax User registration sometimes forbidden 403 error
  
  (Asked by: username_0 on 2018-06-19)
  
  I am experiencing a very weird issue. I have a simple user registration form:
  
  ```
  <form method="post" action="" accept-charset="UTF-8" id="addTeacherForm">
      {{ csrfInput() }}
  
      <input type="hidden" name="action" value="users/save-user" />
      <input type="hidden" name="fields[schoolId][]" value="{{ currentUser.id }}" />
      <input type="hidden" name="groups[]" value="3" />
  
      <div class="form-group">
          <label for="username">Username <span class="text-danger">*</span></label>
          <input id="username" type="text" class="form-control" name="username" required />
      </div>
  
      <div class="form-group">
           <label for="email">E-mailadres <span class="text-danger">*</span></label>
          <input id="email" type="text" class="form-control" name="email" required />
      </div>
  
      <div class="form-group">
          <label for="password">Password <span class="text-danger">*</span></label>
          <input id="password" type="password" class="form-control" name="password" required />
      </div>
  
      <div class="form-group">
          <button type="submit" class="btn btn-primary btn-submit float-right">
              Docent toevoegen
          </button>
      </div>
  </form>
  
  ```
  
  I have an event listener for the form submit and I submit the form using ajax. This code works perfectly most of the time, but sometimes (like 20% of the time) I get a 403 forbidden error in the console. When I comment out the hidden groups[] input field I don't experience this issue at all.
  
  It is also worth noting that even though I get this error the user is created but doesn't get added to the group.
  
  I'm starting to think this is a craft 3 issue.
  
  Can I somehow solve this?
  
  Thanks!
  
  **Tags:** ajax, registration
  
  > **Comments:**
  > **username_1**: As noted in your answer below, this is related to a longstanding bug report. Closing as a "bug report".  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-06-19. Score: 1
  
  > Can I somehow solve this?
  
  Yes by creating a custom Controller. Because the default `UsersController` does the following
  
  ```
  // Don't validate required custom fields if it's public registration
  if (!$thisIsPublicRegistration) {
      $user->setScenario(Element::SCENARIO_LIVE);
  }
  
  ```
  
  without `SCENARIO_LIVE` custom fields won't be stored
  
  > **Comments:**
  > **username_0**: That's not the issue, my custom fields do get stored. The issue is that 20% of the time the user isn't getting assigned to the group and I get a 403 error. The other 80% of the time it works perfectly  
  > **username_2**: Could you eventually tell me what the error message is exactly? You can take a look into your Yii dev Toolbar, in your logs or in your browser network tab. Maybe the user doesn't have the permission to assign to the group  
  > **username_0**: thanks for the quick reply, I took a look at the toolbar and I see the following error: "This action can only be done by an administrator". I am the admin and have full permissions. Also, do you know why this only happens 20% of the time?  
  > **username_2**: When you are dealing with registrations and storing users you'll likely get logged out and in as the other user. So chances are high you have a different account than you expect to have  
  > **username_0**: I don't think that's what's happening because I have full access to the dashboard at all times even after creating the new user(s). I can't be logged in as the new user because the new user account is still set to pending. Thanks for your help though  
  
  ---
  
  ### Answer by username_0 on 2018-06-19. Score: 0
  
  I found out that this has been an issue since December 2017: [github.com/craftcms/cms/issues/2194](http://github.com/craftcms/cms/issues/2194) .I hope they fix it soon. For now I'll go back to craft 2
  
  
  ---
  
  