<p>I have this working in another plugin calling another function:</p>

<pre><code>$forward = $this-&gt;forward('commerce/products/saveProduct', false);
</code></pre>

<p>and it returns to the original controller fine. So, as Brad comments, the forward is actually working as expected but that particular <code>UsersController-&gt;saveUser()</code> function prevents it happening internally.</p>

<p>Within my particular example, I <em>was</em> able to access the original <code>post</code> request and access a <code>userGroupId</code> from the user registration form like so:</p>

<pre><code>    craft()-&gt;on('users.onSaveUser', function (Event $event) {
        if ($event-&gt;params['isNewUser']) {
            if (isset($_POST['userGroup'])) {

                $userGroupId = $_POST['userGroup'];
                $user = $event-&gt;params['user'];

                craft()-&gt;userGroup-&gt;setUserGroup($user, $userGroupId);

            }               
        }
    });
</code></pre>

CC BY-SA 3.0
2017-05-16T10:00:59.520Z
2017-05-16T10:00:59.520Z
Clive Portman
<p>I want to assign a new user to a user group using a variable passed in the frontend registration form. I was going to listen for the OnSaveUser event but I don't think there's a way to get the usergroup from the original post that way(?) so I've instead created a controller that forwards to <code>users/onSaveUser</code> using:</p>

<pre><code>$forward = $this-&gt;forward('users/saveUser', false);
</code></pre>

<p>The idea being I'll then have access to the post after the user has been created. The problem is everything ends here and doesn't reach the rest of my function. Here's my controller:</p>

<pre><code>&lt;?php
namespace Craft;

class UserGroupController extends BaseController
{

    protected $allowAnonymous = true;

    public function actionSaveUser()
    {
        $this-&gt;requirePostRequest();


        $forward = $this-&gt;forward('users/saveUser', false);
        throw new Exception('Made It back!'); // never reached 
        return TRUE;
    }

}
</code></pre>

<p><a href="http://www.yiiframework.com/doc/api/1.1/CController#forward-detail" rel="nofollow noreferrer">According to the Yii docs</a>, <code>false</code> should stop the things ending, right?</p>

CC BY-SA 3.0
2017-05-15T18:48:54.233Z
Just did a simple test with `actionTest1()` forwarding to `actionTest2()` and it works as you'd expect. UsersController->saveUser() is pretty complicated, though.  My guess is that you'd going down one of the branches of it's logic where it's redirecting or ending the request via some other means.  xDebugging should help see what's going on in your case.
Brad Bell
CC BY-SA 4.0
2019-04-19T20:31:06.337Z
What kind of controller works with wild craft. I have bought 4 different ones
D timmons
<users><plugins><yii>
Getting back after forwarding to another controller function
# Getting back after forwarding to another controller function

(Asked by: username_0 on 2017-05-15)

I want to assign a new user to a user group using a variable passed in the frontend registration form. I was going to listen for the OnSaveUser event but I don't think there's a way to get the usergroup from the original post that way(?) so I've instead created a controller that forwards to users/onSaveUser using:
$forward = $this->forward('users/saveUser', false);

The idea being I'll then have access to the post after the user has been created. The problem is everything ends here and doesn't reach the rest of my function. Here's my controller:
requirePostRequest();


        $forward = $this->forward('users/saveUser', false);
        throw new Exception('Made It back!'); // never reached 
        return TRUE;
    }

}

According to the Yii docs, false should stop the things ending, right?

**Tags:** users, plugins, yii

> **Comments:**
> **username_1**: Just did a simple test with `actionTest1()` forwarding to `actionTest2()` and it works as you'd expect. UsersController->saveUser() is pretty complicated, though.  My guess is that you'd going down one of the branches of it's logic where it's redirecting or ending the request via some other means.  xDebugging should help see what's going on in your case.  
> **username_2**: What kind of controller works with wild craft. I have bought 4 different ones  

---

## 1 answers

### Answer by username_0 on 2017-05-16. Score: 1 | Accepted answer

I have this working in another plugin calling another function:
$forward = $this->forward('commerce/products/saveProduct', false);

and it returns to the original controller fine. So, as Brad comments, the forward is actually working as expected but that particular UsersController->saveUser() function prevents it happening internally.
Within my particular example, I was able to access the original post request and access a userGroupId from the user registration form like so:
    craft()->on('users.onSaveUser', function (Event $event) {
        if ($event->params['isNewUser']) {
            if (isset($_POST['userGroup'])) {

                $userGroupId = $_POST['userGroup'];
                $user = $event->params['user'];

                craft()->userGroup->setUserGroup($user, $userGroupId);

            }               
        }
    });


---

