How to redirect to previous page after action?

Hi!
I have question… I created small module where i can add multiple products to the basket (using cmp_basket). Now i need to know how to redirect/return to url from where request was send?

For example i send request from subpage, oxid put products in basket and redirect me to the start page :frowning: I want return to the same page i was send request.

p.s
at this moment i extend cmp_basket and make request with: www.xxx.de/index.php&fnc=methodname&param1=value1

Every page is defined by controller class and many pages also need some kind of ID if it is not defined by the URL.
For example go to a product page and add something to basket. The URL will change from seo friendly category/product.html to something like index.php?cl=details&aid=sg36ei4nd7e6whdzdb. Those are class and ID that define the page and its content.
All you need to do is to submit those as form data and redirect user to this class after you finished your PHP stuff.

Or much simplier approach: submit your data with Ajax, so customer would not leave the current page.

1 Like

I thought i need to use create/extend some controller but i thought i can do some tricky way with only cmp_basket :slight_smile: Ok thanks for replay but… If I chosse option:

  1. I don’t know how to redirect user to previous site should i use header(Location: xxx)? I think there is some better solution. Where should i pass address to redirect? Is there some method in controller or component?
  2. [AJAX] In OXID 4.6.10 i made AJAX solution but in 6 i have some problems. Yesterday i made some research in oxid and there is some solution where form use class: js-oxProductForm. There is also some js file with submit action. Is it correct way? or try to make some ajax with simple jquery? Do you see any clear example of using ajax with form in oxid?
  1. Have a look at tobasket(…) and _getRedirectUrl(). You simply can set before the return:
$sUrl = $_SERVER['HTTP_REFERER'];
oxRegistry::getUtils()->redirect($sUrl, false);

or

$sId = oxRegistry::getConfig()->getRequestParameter('anid');
$oArticle = oxNew('oxArticle');
$oArticle->load($sId);
$sUrl = $oArticle->getLink();
if($url)oxRegistry::getUtils()->redirect($sUrl, false);
2 Likes

Thanks a lot mate :slight_smile: i was watching on it yesterday at night and didn’t see it… i need rest.