Page 1 of 1
I think inadvertently made the BACk button unusable :-(
Posted: Sun Feb 10, 2008 10:21 pm
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...
Re: I think inadvertently made the BACk button unusable :-(
Posted: Sun Feb 10, 2008 10:36 pm
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?

Re: I think inadvertently made the BACk button unusable :-(
Posted: Mon Feb 11, 2008 3:54 am
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.
Re: I think inadvertently made the BACk button unusable :-(
Posted: Mon Feb 11, 2008 9:03 am
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

Re: I think inadvertently made the BACk button unusable :-(
Posted: Mon Feb 11, 2008 4:20 pm
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?
Re: I think inadvertently made the BACk button unusable :-(
Posted: Mon Feb 11, 2008 4:25 pm
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.
Re: I think inadvertently made the BACk button unusable :-(
Posted: Mon Feb 11, 2008 7:15 pm
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.