Page 1 of 1

Make "continue" buttons be "back" buttons

Posted: Fri Jul 23, 2010 5:30 am
by Karen
Instead of taking the user back to the home page, I want those "continue" and "continue shopping" buttons to be back buttons for the barely-web-literate. (All except the ones inside the checkout process itself, of course).

Can anyone tell me how to change this? Is it on a template-by-template basis?

Found this answer from a year ago, though Daniel had said he would add it to the next release. Is this still the best answer?

http://forum.opencart.com/viewtopic.php ... 574#p27486

Re: Make "continue" buttons be "back" buttons

Posted: Fri Jul 23, 2010 6:30 am
by Karen
Based on the above, I have found 4 controller files I think I'd want to change. Before I totally nuke my cart, can someone tell me whether this is the right coding to change, and the right change to make?

catalog/controller/checkout/cart.php
catalog/controller/error/not_found.php
catalog/controller/information/information.php

For every instance in the above files where the code reads

Code: Select all

$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
I would substitute:

Code: Select all

$this->data['continue'] = HTTP_SERVER . "history.back()";
Yes, no? Is there a space, a period, or quote marks out of place here?

Thanks in advance, all you coding wizards.

Re: Make "continue" buttons be "back" buttons

Posted: Fri Jul 23, 2010 7:38 am
by JAY6390

Code: Select all

$this->data['continue'] = HTTP_SERVER . "history.back()"; 
should be

Code: Select all

$this->data['continue'] = "history.back()"; 

Re: Make "continue" buttons be "back" buttons

Posted: Fri Jul 23, 2010 10:00 am
by Karen
Hmmm, that doesn't work, either. Instead of trying to go back, it tries to go to http://www.mydomain.com/history.back(), which of course doesn't exist.

In poking around the web, I found some (admittedly old) info on Webmaster World: "If you use sessions then just remember the last page in your session container and use that URI." I don't know what that means, but I did see some code in those controller files about sessions.

I also saw the warning about: "I´d use the $_SERVER['HTTP_REFERER'] superglobal just to be sure. Checking whether the referrer is a valid URI and on your domain might be a good idea as well. After all this could be anything, so simply echoing it will open up your site to all kinds of code injections vulnerabilities."

Apparently this coding of a back button is way more complicated than I thought ???
But I'd still like to do it if someone can give me the answers.

Re: Make "continue" buttons be "back" buttons

Posted: Fri Jul 23, 2010 4:01 pm
by fido-x
Don't add the "history.back()" into the controller. Do it in the template file.
Change:

Code: Select all

<a onclick="location = '<?php echo str_replace('&', '&', $continue); ?>'" class="button">
to:

Code: Select all

<a onclick="history.back();" class="button"> 

Re: Make "continue" buttons be "back" buttons

Posted: Fri Jul 23, 2010 4:51 pm
by mystifier
I use back buttons in several pages as follows which works great:

Code: Select all

<a href="javascript:history.go(-1)"  onMouseOver="self.status=document.referrer;return true" class="button"><span>Continue</span></a>   
(I am not clever enough to write this by the way... I got it from somewhere else).

Re: Make "continue" buttons be "back" buttons

Posted: Sat Jul 24, 2010 2:32 am
by Karen
Thanks to both of you!

I'll give these a try.

Re: Make "continue" buttons be "back" buttons

Posted: Sat Jul 24, 2010 12:00 pm
by fido-x
My personal choice would be to use the "onclick" method rather than the "href" method, simply because the "onclick" hides the link, whereas the "href" displays the link in the status bar at the bottom of your browser window.

Re: Make "continue" buttons be "back" buttons

Posted: Sat Jul 24, 2010 1:34 pm
by Karen
Thanks for the info. I did use the onclick, because it was a straight substitution. I really appreciate all the help (and so will everyone else who's looking to do this)!