10

So, I'm struggling with this, I've got an observer set up to trigger whenever customer/account/login is hit. Firebug clearly shows that I'm POSTing data to this URL and I'm not able to read said POST data in my observer method.

Observer method:

public function checkCustomerLogin($observer) { Mage::log("event observed"); $controller = $observer->getControllerAction(); Mage::log(print_r($controller->getRequest()->getPost(), true)); return $this; } 

Example log result:

2014-03-11T11:46:38+00:00 DEBUG (7): event observed 2014-03-11T11:46:38+00:00 DEBUG (7): Array ( ) 

My observer is configured to trigger on controller_action_predispatch_customer_account_login. Clearly I'm doing something wrong here seeing as how I just can't get my POST data (I've tried a few other desperate approaches but from what I can tell this is how you're "supposed" to get a controller and the POST data in an observer method).

2 Answers 2

26

Use Mage::app()->getRequest()->getParams()

It will return array of all parameters sent to called controller's action

Hope this helps you

Sign up to request clarification or add additional context in comments.

6 Comments

Tried that one just now, still just an empty array.
Try Mage::log(Mage::app()->getRequest()->getControllerName()); and Mage::log(Mage::app()->getRequest()->getActionName()); and check log that your desired controller is trapped by observer or not.
Controller name is account and action name is login.
You will not find any post data here, since in account controller's login action, no values are passed in post. You should use your observer for loginPostAction (I think) to get values in params.
Ah, loginPost, I keep forgetting that one exists. That worked a lot better.
|
6

instead of controller use app so

instead of

Mage::log(print_r($controller->getRequest()->getPost(), true)); 

change to

Mage::log(print_r(Mage::app()->getRequest()->getPost(), true)); 

So that instead of controller you are using $app to get post details.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.