I created an Access database which the customer wanted to access from the web. What's more, they wanted the web version to look exactly like the Access version - so they wanted to click buttons rather than links to pages. I created an index page that presented buttons and used the Header function to decide where to go. It looks like this:
Buffer the page becuse if ANYTHING is output to the browser before the relocation - it wont work This is at the very top of the .php file.
<?php
ob_start();
// Check whether we are returning from a button-press
// The HTML Form Buttons are simply called Opt1, Opt2 ...Optn
//If $opt is NOT still zero (a button was clicked), determine which one...and go there.
if($opt)
{
switch ($opt) {
case 1 :
header("Location: http://www.yourpage.php?var1=$var1&var2=$var2);
exit;
case 2 :
header("Location: http://www.yourpage2.php?var1=$var1&var2=$var2);
exit;
case 3 :
header("Location: http://www.yourpage3.php?var1=$var1&var2=$var2);
exit;
case 4 :
header("Location: http://www.yourpage4.php?var1=$var1);
exit;
case 5 :
// Cases 5 & 6 included for future expansion
break;
case 6 :
break;
}
exit;
}
// If $opt is still Zero - no button has been pressed
// so your visitor has just arrived or clicked refresh
// or back.
else
{
?>
// Finish off the php and start the HTML (where the buttons are presented in an ordinary HTML form [they are ALL Submit buttons].)
<html>
<head>
...
etc.
This has several advantages. No links, just buttons. One index page allows parameters to be set (using check boxes etc) before choosing a page to go to, which negates the need to quiz the visitor for variables when (s)he gets there.
Jon Slack wrote :1068
I should perhaps have mentioned that the action= part of the form declaration is PHP_SELF or the URL of this index page so that upon pressing any of the 6 submit buttons always beings the visitor back to the same page.
:o)
matthew waygood wrote :1069
Your example is a bit half-hearted. It doesnt contain full code as an example should. It just looks like an example of a switch statement. There is no reference to $_GET to process the passed values or how you are showing the buttons.
Surely a simpler example would be to replace all links with forms.