Log in

View Full Version : Input Type = Multiple Radio redirect



jbrill1012
02-16-2012, 05:13 AM
Just wondering how to go about this...

I have 3 radio buttons on a site and depending on which radio button is selected I want it to redirect upon submit to one of three web pages.

such as:

<?PHP

if (isset ($POST[submit1])) {

$which_site = "x,y,z"
if x then 1.php
else if y then 2.php
else if z then 3.php

}
?>

<body>
<form name ="sites" method ="post" action = "$which_site">
<input type ="radio" name ="sites" value ="#">Site 1
<input type ="radio" name ="sites" value ="#">Site 2
<input type ="radio" name ="sites" value ="#">Site 3
<input type ="submit" name ="submit1" value ="Submit">
</form>

Yes I know this would be easier to do with just straight html, but it will help me learn more further along in building other pages for this site. I will later be building more php code that will redirect to a webpage with form output information being pulled from a database. Yes I also know the code above is no where near correct it's just an example of what I think it may look like.

jscheuer1
02-16-2012, 12:06 PM
<?php
if (isset ($_POST['sites'])) {
header('Location: ' . $_POST['sites']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Switch to Location</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="radio" name="sites" value="http://www.google.com/">Site 1
<input type="radio" name="sites" value="http://www.dynamicdrive.com/">Site 2
<input type="radio" name="sites" value="http://en.wikipedia.org/wiki/Main_Page">Site 3
<input type="submit" value="Submit"><br>
<p><input type="reset"></p>
</form>
</body>
</html>