Sunday, July 6, 2008

Redirect a page OnSubmit using radio buttons and php

Do you need a simple form which redirect to a new page when you select a relevant Radio button and submit? Take a look at the following code, pretty simple :)


<?php

//check if submit button is pressed
if(isset($_POST['sub']))
{
$path_id = $_POST['test'];//get selected radio button value

if($path_id == 1)
{
header("Location: page1.php");//redirect to the new page
}
else if($path_id == 2)
{
header("Location: page2.php");
}
else if($path_id == 3)
{
header("Location: page3.php");
}

}

?>

<html>
<head>
<title>test</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="test.php">
Form1:
<input type="radio" name="test" id="test" value="1" />

Form2:
<input type="radio" name="test" id="test" value="2" />

Form3:
<input type="radio" name="test" id="test" value="3" />
<br />
<br />

<input type="submit" name="sub" value="submit" />
</form>
</body>
</html>




Get custom programming done at GetAFreelancer.com!

2 comments:

  1. Hi, Its good code eassy one
    Thanx

    ReplyDelete
  2. I needed to see your option of using numerics as the input values! Thanks so much!

    Lisa

    ReplyDelete