Question

I currently have a login form which opens when a customer clicks a link in the header (instead of going off to /customer/login). Apart from a few field ID's, it's pretty much unchanged from customer/templates/form/login.phtml.

How do I call the current url into the form so it doesn't redirect to the account page? (I have disabled that feature in the CMS also)

I know from various tutorials this can be achieved using this as url:

$url  = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
$login_url = $block->getUrl('customer/account/login', array('referer' => base64_encode($url)));

But I'm not quite sure how to integrate that into the custom form.

Thanks

Was it helpful?

Solution

After looking at the action on the login page, I realised I was overthinking it. I could actually apply the same logic.

So essentially it's the same as the code posted in the question, but replacing customer/account/login with customer/account/loginPost

At the top of my modal, I used this:

$url  = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
$login_url = $block->getUrl('customer/account/loginPost', array('referer' => base64_encode($url)));

And simply used the $login_url as the action for that form.

Woo!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top