Getting info from radio buttons.
Posted: Sat Feb 10, 2007 5:20 pm
I have no idea how to do it. =o Normally you just set a variable to $_POST, but I'm not sure how this posts, and I have 5 options I don't know how to select, either.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<p>
<label>
<input type="radio" name="RadioGroup" value="1" />
first</label>
<br />
<label>
<input type="radio" name="RadioGroup" value="2" />
second</label>
<br />
</p>Code: Select all
if(isset($_POST['RadioGroup'])){
$radio = $_POST['RadioGroup'];
if($radio == "1") {
//.. do something
}elseif($radio == "2"){
//..do something else
}
}Code: Select all
<form action="confmonster.php">
<center>
<image width="12%" height="12%" src="monsters/evilEgg.png"><input type="radio" name="choice" value="1"> Evil
<image width="12%" height="12%" src="monsters/goodEgg.png"><input type="radio" name="choice" value="2"> Good
<br>
<image width="12%" height="12%" src="monsters/cuteEgg.png"><input type="radio" name="choice" value="3"> Cute
<image width="12%" height="12%" src="monsters/normalEgg.png"><input type="radio" name="choice" value="4"> Worker
<br>
<image width="12%" height="12%" src="monsters/workEgg.png"><input type="radio" name="choice" value="5"> Normal<br><br>
<input type="submit" name="choice" value="I choose this one!"></center>
</form>Code: Select all
$chosenmonster = $_POST["choice"];
if (!isset($chosenmonster));
die("Chosen monster... is not set.");
if (empty($chosenmonster))
die("Erm, you should probably pick the egg you'd like first. ");
// CHOOSING THE MONSTER. <333
// 1 = EVIL 2 = GOOD 3 = CUTE 4 = WORKER 5 = NORMAL
if ($chosenmonster = 1)
die("Yup, it works.");Code: Select all
method="post"Code: Select all
//$chosenmonster = $_POST["choice"];
if (!isset($_POST["choice"])){ die("Chosen monster... is not set."); }
// if (empty($chosenmonster))
// die("Erm, you should probably pick the egg you'd like first. ");
// CHOOSING THE MONSTER. <333
// 1 = EVIL 2 = GOOD 3 = CUTE 4 = WORKER 5 = NORMAL
if (isset($_POST["choice"])){
if($_POST["choice"] == "1"){
die("Yup, it works.");
}
//......... more code
}