<p>If anyone comes here looking for this answer for Craft 3 the function you are looking for is <code>Craft::$app-&gt;getRequest()-&gt;getIsCpRequest()</code></p>

CC BY-SA 4.0
2019-01-10T08:43:05.283Z
2019-01-10T08:43:05.283Z
nfourtythree
<p>Yes there is, <code>craft()-&gt;request-&gt;isCpRequest()</code> returns whether the request is from the CP or not.</p>

CC BY-SA 3.0
2016-05-09T12:58:24.573Z
2016-05-09T12:58:24.573Z
carlcs
<p>We're building a content platform for a bank for a client of us. One required feature lets relationship managers add clients (members) to the platform which get assigned a specific group.</p>

<p>We listen to the <code>users.onSaveUser</code> event and when the specific group is chosen and the user gets added via the CP there should be sent out a specific email to that client. This is the code I have so far:</p>

<pre><code>public function initRmAddsClient()
{
    craft()-&gt;on('users.onSaveUser', function(Event $event) {

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

        if ($event-&gt;params['isNewUser'])
        {
            //get new user group from form post
            $groups = craft()-&gt;request-&gt;getPost('groups');
            if ($groups) 
            {
                if (count($groups) &gt; 0) 
                {
                    $userGroup = craft()-&gt;userGroups-&gt;getGroupById($groups[0]);

                    if ($userGroup-&gt;handle == 'premium' || $userGroup-&gt;handle == 'private') 
                    {
                        craft()-&gt;email-&gt;sendEmailByKey($user, 'rm_adds_client', array(
                            'user' =&gt; $user,
                            'link' =&gt; TemplateHelper::getRaw(craft()-&gt;users-&gt;getPasswordResetUrl($user)),
                            'rm' =&gt; craft()-&gt;userSession-&gt;getUser(),
                        ));
                    }
                }

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

<p>I just want to add one extra check if the submission is done via the control panel since public registration is enabled as well.</p>

<p>Is there an easy check for that?
Thanks</p>

<control-panel><emails><events><user-groups>
Is there a way to detect if a action is triggered from a control panel form?
# Is there a way to detect if a action is triggered from a control panel form?

(Asked by: username_0 on 2016-05-09)

We're building a content platform for a bank for a client of us. One required feature lets relationship managers add clients (members) to the platform which get assigned a specific group.
We listen to the users.onSaveUser event and when the specific group is chosen and the user gets added via the CP there should be sent out a specific email to that client. This is the code I have so far:
public function initRmAddsClient()
{
    craft()->on('users.onSaveUser', function(Event $event) {

        $user = $event->params['user'];

        if ($event->params['isNewUser'])
        {
            //get new user group from form post
            $groups = craft()->request->getPost('groups');
            if ($groups) 
            {
                if (count($groups) > 0) 
                {
                    $userGroup = craft()->userGroups->getGroupById($groups[0]);

                    if ($userGroup->handle == 'premium' || $userGroup->handle == 'private') 
                    {
                        craft()->email->sendEmailByKey($user, 'rm_adds_client', array(
                            'user' => $user,
                            'link' => TemplateHelper::getRaw(craft()->users->getPasswordResetUrl($user)),
                            'rm' => craft()->userSession->getUser(),
                        ));
                    }
                }

            }
        }
    });
}

I just want to add one extra check if the submission is done via the control panel since public registration is enabled as well.
Is there an easy check for that?
Thanks

**Tags:** control-panel, emails, events, user-groups


---

## 2 answers

### Answer by username_2 on 2016-05-09. Score: 6 | Accepted answer

Yes there is, `craft()->request->isCpRequest()` returns whether the request is from the CP or not.


---

### Answer by username_1 on 2019-01-10. Score: 11

If anyone comes here looking for this answer for Craft 3 the function you are looking for is `Craft::$app->getRequest()->getIsCpRequest()`


---

