Getting info from radio buttons.
Moderator: General Moderators
-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
Getting info from radio buttons.
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.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
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
}
}-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
Ugh! Again! It can't just WORK.
That's what my form looks like (ignore the images and stuff :p) but when I send it on over to confmonster.php, it has no value. I think it's the submit button. The confmonster.php looks like:
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.");add this to the form
then
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
}-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am