Issue
I was wondering if it is possible to make each radio button in a form link to a different action php page? say if I had 2 radio buttons, one named 'basketball' and one named 'football' would I be able to have them link to different php? here is my code;
<form action="football.php" method="post">
<p>Please select your first Sport:</p>
<input type="radio" name="sport" value="football">Football<br></input>
<input type="radio" name="sport" value="basketball">Basketball<br></input>
<input type="radio" name="sport" value="tennis">Tennis</input>
<br><input type="Submit" name="Submit" value="Submit"></form>
Solution
Is there any reason they need to be distinct pages?
form.php
<form action="sport.php" method="post">
<p>Please select your first Sport:</p>
<input type="radio" name="sport" value="football">Football<br></input>
<input type="radio" name="sport" value="basketball">Basketball<br></input>
<input type="radio" name="sport" value="tennis">Tennis</input>
<br><input type="Submit" name="Submit" value="Submit"></form>
sport.php
<?php
if (isset($_POST["sport"])
&& $_POST["sport"] == "football") {
//logic specific for football
} else if (isset($_POST["sport"])
&& $_POST["sport"] == "basketball") {
//logic specific for basketball
} else if (isset($_POST["sport"])
&& $_POST["sport"] == "tennis") {
//logic specific for tennis
} else {
//die or some kind of error handling can be done
}
?>
If they absolutely need to be different pages, you can do something like the below:
sport.php
<?php
echo "<meta http-equiv='refresh' content='0;url=./dir/subdir/".$_POST["sport"].".php'/>";
//so if posted form data == football, redirect to football.php, etc
?>
Sure it lacks finesse, but you won't be able to get your desired outcome otherwise, unless you use jQuery/JS.
Answered By - gator
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.