2

I have same login form of magento in two different phtml pages(one is default login page and other is my custom phtml page but the login code is same since i copied from default login page). Now what I want is when user is logging with default login page redirection is to dashboard(which is by default) and when user is logging with my custom login form page, I want him to redirected to other page other than the dashboard.Is it possible?If yes then please elaborate how?

1
  • yes it is possible
    – Abdul
    Nov 17, 2015 at 11:34

1 Answer 1

2

[Edited:]

In order to full fill your requirement, need to use Event/Observer.

  • First create a custom input hidden field (custom_redirect) at custom phtml Input this field: <input name="custom_redirect" type="hidden" value="1"/>

  • Then using customer_login event for redirect to custom page on basic of custom_redirect.

At event fire an observer which redirect to yourcustom url page on basic of custom_redirect input value using magento FrontController prediction action

Mage::app()->getFrontController()->getResponse()->setRedirect("YOUR_URL");

config.xml:

 <frontend>
        <events>
            <customer_login>
                <observers>
                    <redirect_to_anthor_page>
                        <class>StackExchange_Magento90351_Model_Observer</class>
                        <method>redirectNotLogged</method>
                    </redirect_to_anthor_page>
                </observers>
            </customer_login>
        </events>
    </frontend>

Observer code:

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Observer
 *
 * @author work
 */
class StackExchange_Magento90351_Model_Observer {
    //put your code here
 public function redirectNotLogged(Varien_Event_Observer $observer){
     if(Mage::app()->getRequest()->getParam('custom_redirect')==1):
        Mage::app()->getResponse()->setRedirect(Mage::getUrl('affiliate/index/d‌ashboard'))
            ->sendResponse();
        exit;
       endif; 
     } 

}
10
  • I tried to implement your method but when I am adding events to config.xml my custom form page showing 404
    – Akash
    Nov 17, 2015 at 12:22
  • after fixing 1 spelling mistake 404 gone but it's not redirecting to my page instead goin to dashboard
    – Akash
    Nov 17, 2015 at 12:26
  • i tried to use die() and found that is not entering if condition
    – Akash
    Nov 17, 2015 at 12:31
  • please change to Mage::app()->getFrontController()->getResponse()->setRedirect("YOUR_URL");
    – Amit Bera
    Nov 17, 2015 at 12:33
  • yes i have already done but its not entering the if condition.
    – Akash
    Nov 17, 2015 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.