<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>

CC BY-SA 4.0
2018-06-19T13:04:37.933Z
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
Branko
CC BY-SA 4.0
2018-06-19T13:06:01.120Z
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
Robin Schambach
CC BY-SA 4.0
2018-06-19T13:14:11.663Z
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?
Branko
CC BY-SA 4.0
2018-06-19T13:16:31.200Z
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
Robin Schambach
CC BY-SA 4.0
2018-06-19T13:21:30.713Z
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
Branko
CC BY-SA 4.0
2018-06-19T11:49:39.943Z
2018-06-19T11:49:39.943Z
Robin Schambach
<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>

CC BY-SA 4.0
2018-06-19T13:42:39.137Z
2018-06-19T13:42:39.137Z
Branko
<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>

CC BY-SA 4.0
2018-06-26T04:16:47.603Z
As noted in your answer below, this is related to a longstanding bug report. Closing as a "bug report".
Lindsey D
<ajax><registration>
Ajax User registration sometimes forbidden 403 error
# 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:

    {{ csrfInput() }}

    
    
    

    
        Username *
        
    

    
         E-mailadres *
        
    

    
        Password *
        
    

    
        
            Docent toevoegen
        
    


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


---

