<p>You can set a variable in your craft/config/general.php. Here is the option taken from the default config file which is located here <code>craft/app/etc/config/defaults/general.php</code>:</p>

<p><strong>Updated:</strong></p>

<pre><code>/**
 * The path that users should be redirected to after logging in from the front-end site.
 *
 * This setting will also come into effect if the user visits the Login page (as specified by the loginPath config
 * setting) when they are already logged in.
 */
'postLoginRedirect' =&gt; '',
</code></pre>

<p>From that page you can also easily route them to another page based on conditionals in twig using <code>{% if something %}{% redirect url %}{% endif %}</code>. </p>

<p>And although I haven't tried this personally, it looks like (<a href="https://craftcms.stackexchange.com/questions/71/is-it-possible-to-show-a-successful-logout-message/77#77">based on this answer</a>) you can redirect from within your plugin using the following (perhaps only from a controller however): </p>

<pre><code>$this-&gt;redirect('/apply');
</code></pre>

<p>I also see in UserSessionService.php line 371 the following which should also work:</p>

<pre><code>$url = UrlHelper::getUrl(craft()-&gt;config-&gt;getLoginPath());
craft()-&gt;request-&gt;redirect($url);
</code></pre>

CC BY-SA 3.0
2014-11-04T18:54:09.147Z
Isn't account activation when an account is initially activated? Or does it refer to when the user logs in? Is there a way to set different redirect paths for different forms with the config file method?
Anson LeClair
CC BY-SA 3.0
2014-11-04T19:29:41.337Z
Unfortunately $this->redirect('/apply'); did not work in my plugin. Perhaps $this->redirect() can only be used in a controller. It throws errors when used in an init() function within the main plugin file.
Anson LeClair
CC BY-SA 3.0
2014-11-04T21:59:40.207Z
You're right on both counts. Sorry. I grabbed the wrong variable. Use `postLoginRedirect` instead. I have updated the answer.
Douglas McDonald
CC BY-SA 3.0
2014-11-04T15:42:59.523Z
2014-11-04T22:18:16.730Z
2017-04-13T12:51:00.160Z
Douglas McDonald
<p>Is there a way to send the user to a different page than the control panel when logging in from a custom login form?</p>

<p>I've tried..</p>

<pre><code>&lt;form method="post" action="" accept-charset="UTF-8"&gt;
    &lt;input type="hidden" name="action" value="users/login"&gt;
    &lt;input type="hidden" name="redirect" value="apply"&gt;
</code></pre>

<p>I've also tried setting the returnUrl session in a login event within a plugin. There's a bit left to do in the init function but you get the idea. Currently the code should redirect all logins. </p>

<pre><code>public function init()
{
    craft()-&gt;on('userSession.onLogin', function(Event $event) {
        // load the user info and determine user group
        // if part of applicant user group
        // load any existing unfinished applications
        // set a session for the unfinished application
        // redirect to /apply which should load the unfinished application
        craft()-&gt;session['returnUrl'] = "/apply";
    });
}
</code></pre>

CC BY-SA 3.0
2014-11-04T19:27:24.597Z
In the end this ended up being a small error with the path in the returnUrl. Simply changing it to craft()->session['returnUrl'] = "apply"; appears to have solved the problem. I'm still curious if there's a way to set this in the custom login template or if it has to be done in a plugin.
Anson LeClair
<plugin-development><login>
How do I set where the user is sent from a custom login form?
# How do I set where the user is sent from a custom login form?

(Asked by: username_0 on 2014-11-04)

Is there a way to send the user to a different page than the control panel when logging in from a custom login form?
I've tried..

    
    

I've also tried setting the returnUrl session in a login event within a plugin. There's a bit left to do in the init function but you get the idea. Currently the code should redirect all logins. 
public function init()
{
    craft()->on('userSession.onLogin', function(Event $event) {
        // load the user info and determine user group
        // if part of applicant user group
        // load any existing unfinished applications
        // set a session for the unfinished application
        // redirect to /apply which should load the unfinished application
        craft()->session['returnUrl'] = "/apply";
    });
}

**Tags:** plugin-development, login

> **Comments:**
> **username_0**: In the end this ended up being a small error with the path in the returnUrl. Simply changing it to craft()->session['returnUrl'] = "apply"; appears to have solved the problem. I'm still curious if there's a way to set this in the custom login template or if it has to be done in a plugin.  

---

## 1 answers

### Answer by username_1 on 2014-11-04. Score: 4

You can set a variable in your craft/config/general.php. Here is the option taken from the default config file which is located here craft/app/etc/config/defaults/general.php:
Updated:
/**
 * The path that users should be redirected to after logging in from the front-end site.
 *
 * This setting will also come into effect if the user visits the Login page (as specified by the loginPath config
 * setting) when they are already logged in.
 */
'postLoginRedirect' => '',

From that page you can also easily route them to another page based on conditionals in twig using {% if something %}{% redirect url %}{% endif %}. 
And although I haven't tried this personally, it looks like (based on this answer) you can redirect from within your plugin using the following (perhaps only from a controller however): 
$this->redirect('/apply');

I also see in UserSessionService.php line 371 the following which should also work:
$url = UrlHelper::getUrl(craft()->config->getLoginPath());
craft()->request->redirect($url);

> **Comments:**
> **username_0**: Isn't account activation when an account is initially activated? Or does it refer to when the user logs in? Is there a way to set different redirect paths for different forms with the config file method?  
> **username_0**: Unfortunately $this->redirect('/apply'); did not work in my plugin. Perhaps $this->redirect() can only be used in a controller. It throws errors when used in an init() function within the main plugin file.  
> **username_1**: You're right on both counts. Sorry. I grabbed the wrong variable. Use `postLoginRedirect` instead. I have updated the answer.  

---

