I think inadvertently made the BACk button unusable :-(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DrX
Forum Newbie
Posts: 3
Joined: Sun Feb 10, 2008 10:12 pm

I think inadvertently made the BACk button unusable :-(

Post by DrX »

What have I done :( :(

Ok, I coded up a page that generates different content on the fly based on user input via forms, links etc.
I capture values in $_POST and $_GET variables, and based on these values I generate different content.

I just realized that due to this architecture, the BACK button may now be useless.
There is just one page (index.php) so there will be no going BACK, since it's the same page.

Someone must have run into this issue before. What is (is there) the solution? Or do I, and users of the site have to deal with this.
I don't think users will be pleased if they cannot navigate BACK.

I am a PHP and HTML novice, so there is probably something I am missing here.
Please advise.

Regards...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: I think inadvertently made the BACk button unusable :-(

Post by Christopher »

It's Dr X's Monster!

Have you actually tried this monstrosity you have created to see if the Back button still works? ;)
(#10850)
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: I think inadvertently made the BACk button unusable :-(

Post by Rovas »

:) It' s still works press it twice in IE. It does this because of the mode in which POST sends the data to the web server in a associative array. Use with care POST in your code.
DrX
Forum Newbie
Posts: 3
Joined: Sun Feb 10, 2008 10:12 pm

Re: I think inadvertently made the BACk button unusable :-(

Post by DrX »

:( :( :(
Yeah I tried it in a browser.

Based on values captured in $_POST & $_GET, I make assignments/manipulations to class objects.
I then draw the screen based on the state of the objects.
In order for the back button to work, I guess I have to save the old state of the objects. GAAA ... what a monster I have created. But how would I even recognize that BACK has been pressed. It's not like there is a BACK/FORWARD event. Or is there.
Shoot me :(
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: I think inadvertently made the BACk button unusable :-(

Post by Stryks »

I'm not sure if it will help in this instance, but you could perhaps just define your view using $_GET arguments, and then when $_POST values are recieved, compile the appropriate $_GET values and pass them to a header redirect.

Code: Select all

if(isset($_POST['whatever'])) { 
   // header redirect based on current $_GET and $_POST values
   header('Location: http://www.mysite.com/index.php?view=' . $_POST['whatever']);
   exit();
}
if(isset($_GET['whatever'])) {
   // display data as required
} 
 
This way, the form posts are skipped in the 'back' history, leaving just the individual pages as viewed. In other words, all page views would be non form submits.

That code is totally untested, and you would of course need to sanitize that $_POST and $_GET, but you get the drift.

Any help?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: I think inadvertently made the BACk button unusable :-(

Post by Christopher »

Yes, Stryks shows what is a best practice with web forms. You submit the form to itself until there are no errors, then you redirect to a different page to continue or display a success page. The redirect causes the Back button to work properly.
(#10850)
DrX
Forum Newbie
Posts: 3
Joined: Sun Feb 10, 2008 10:12 pm

Re: I think inadvertently made the BACk button unusable :-(

Post by DrX »

Thanks.
I was thinking about doing exactly that. Glad to know what I was thinking wasn't a crazy idea.
I'll proceed and find out if it works.
Post Reply