{"id":1461,"date":"2017-02-17T03:40:14","date_gmt":"2017-02-16T21:40:14","guid":{"rendered":"http:\/\/promincproductions.com\/blog\/?p=1461"},"modified":"2017-02-17T03:40:34","modified_gmt":"2017-02-16T21:40:34","slug":"magento-1x-redirect-login-form-login","status":"publish","type":"post","link":"https:\/\/promincproductions.com\/blog\/magento-1x-redirect-login-form-login\/","title":{"rendered":"Magento 1.x Redirect Login Form After Login"},"content":{"rendered":"<p>The problem is simple:<\/p>\n<ul>\n<li>After a user logs into the website, redirect them to a specific URL.<\/li>\n<\/ul>\n<p>The solutions across the internet are vast and code heavy. \u00a0But this solution really only requires a simple change to your template file.<\/p>\n<p>In the login template:<\/p>\n<blockquote>\n<p>persistent\/customer\/form\/login.phtml<\/p>\n<\/blockquote>\n<p>Update the form action to include your specific redirect path.<\/p>\n<p>This is what exists currently:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;form action=\"&lt;?php echo $this-&gt;getPostActionUrl() ?&gt;\" method=\"post\" id=\"login-form\" class=\"scaffold-form\" autocomplete=\"off\" &gt;<\/pre>\n<p>What I suggest is writing your redirect into a PHP variable, and then apply that to the action parameter. \u00a0Like this:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?php\r\n\/\/ set redirect URL\r\n$session-&gt;setBeforeAuthUrl( Mage::getBaseUrl() );\r\n$redirectUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB,array('_secure'=&gt;true)).'your-redirect-path.html';\r\n$formActionUrl = $this-&gt;getPostActionUrl() . ( strpos( $this-&gt;getPostActionUrl(), \"?\" ) &gt; 0 ? \"&amp;\" : \"?\" ) . \"referer=\" . Mage::helper('core')-&gt;urlEncode( $redirectUrl );\r\n?&gt;\r\n\r\n&lt;form action=\"&lt;?php echo $formActionUrl ?&gt;\" method=\"post\" id=\"login-form\" class=\"scaffold-form\" autocomplete=\"off\" &gt;<\/pre>\n<p>Let me explain what is happening here a bit.<\/p>\n<ul>\n<li>The core Magento code expects the\u00a0<strong>$session-&gt;setBeforeAuthUrl<\/strong> to be set to respect the\u00a0<strong>referer<\/strong> query parameter. \u00a0For that reason, I simply set it to the homepage. \u00a0This is really just a failsafe in-case something goes wrong.<\/li>\n<li>The\u00a0<strong>$redirectUrl<\/strong> is the URL you&#8217;d like your visitors to land on after logging in.<\/li>\n<li>The\u00a0<strong>$formActionUrl<\/strong> simply takes the current form post URL that exists and adds the\u00a0<strong>referer<\/strong> query parameter with your redirect URL. \u00a0The one bit of &#8220;trickery&#8221; here is to pass it through Magento&#8217;s\u00a0<strong>urlEncode<\/strong> function in the core helper which base64 encodes the URL.\n<ul>\n<li>If you&#8217;re asking <em>what does base64 encode mean\/do???<\/em>, don&#8217;t worry it&#8217;s nothing big you need to worry about. \u00a0But simply put, it turns the url into garbly-gook &#8211; which is how Magento expects the URL to be formatted. \u00a0Later, Magento will un-garbly-gook (yes, a technical term) the URL on the backend so they know what it means.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>And that&#8217;s it &#8211; simple as that. \u00a0No modules, fancy trickery, etc. \u00a0But of course remember to copy this template to your theme folder (don&#8217;t edit in the <strong>base<\/strong> or\u00a0<strong>default<\/strong> directory) before making these changes.<\/p>\n<p>I hope that helps someone!<\/p>","protected":false},"excerpt":{"rendered":"<p>The problem is simple: After a user logs into the website, redirect them to a specific URL. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[46,5],"tags":[],"class_list":["post-1461","post","type-post","status-publish","format-standard","hentry","category-magento","category-website-development"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4BbcR-nz","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/comments?post=1461"}],"version-history":[{"count":1,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1461\/revisions"}],"predecessor-version":[{"id":1462,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/1461\/revisions\/1462"}],"wp:attachment":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media?parent=1461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/categories?post=1461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/tags?post=1461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}