PDA

View Full Version : Non-js dynamic choice of "action=" in forms!



djlebarron
27 Jun 2009, 11:05 AM
I asked around about this months ago, and was told (by everyone that responded) that I would have to use JavaScript onClick or onChange to do it.

Not so.

I've just had another one of those exhilerating breakthrough moments that make this all seem worthwhile.

Using only php, I was able to choose which of three pages to send my form to by using radio buttons that are part of the actual form itself.

I first made a made an "intermediary page" (really just a file) called "trans.php" to send my form to. In my form, I set action = "trans.php". This is trans.php:
<?php
session_start();
$_SESSION[entertainer]=$_POST[entertainer];
$a = $_POST[SITE];
header("location: $a");
?>No <html>, no tags, nothing but the above. "SITE" was the name of my three radio buttons (my url choices) on my form page. I then put <?php session_start(); ?> at the very top of each of the pages that are my choices for the "header("location: $a");" before ANYTHING else including my doctype, html tag, etc. I put <?php echo $_SESSION[entertainer] ?> in the appropriate place on each of the three potential ultimate destination pages where I wanted to echo the variable passed from the form, and POOF!, it freaking worked!
I've gone even deeper into the rabbit hole and I'm nuts about it! http://www.greentreesites.com/matrix.jpg