Page 1 of 1
Get Radio Button value using php $_GET
Posted: Sat Apr 23, 2011 12:31 am
by madzmar25
Hi Guys i have a problem of retrieving the value of the radio button via a $_GET[] function... the use of button to retrieve the value of the radiobutton is no problem but i cant do it and i cant find a descend reply regarding this problem when it comes to get method... here is a simple code i hope you can help me guys
***** PLEASE USE THE PHP CODE TAG *****
Code: Select all
<?PHP
if (isset($_GET["submit"])) {
echo $_GET["myradio"];
}
?>
<html>
<head>
</head>
<body>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="get">
One <input type="radio" name="myradio" value="one">
Two <input type="radio" name="myradio" value="two">
<a href="<?php echo $_SERVER["PHP_SELF"] ?>" name="submit">test </a>
</form>
</body>
</html>
Re: Get Radio Button value using php $_GET
Posted: Sat Apr 23, 2011 12:38 am
by Christopher
You are submitting your form with the POST method -- the values of the form will be put in to $_POST. If you want to use GET then set method="get" in the form.
Re: Get Radio Button value using php $_GET
Posted: Sat Apr 23, 2011 12:45 am
by madzmar25
i tried it and used the get in the form instead of post but still i cant retrieve the value... please help
Re: Get Radio Button value using php $_GET
Posted: Sat Apr 23, 2011 4:33 am
by Gopesh
hi,Instead of using a href in form tag,use submit button here is the code.
Code: Select all
<?PHP
if (isset($_GET["submit"])) {
echo $_GET["myradio"];
}
?>
<html>
<head>
</head>
<body>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="get">
One <input type="radio" name="myradio" value="one">
Two <input type="radio" name="myradio" value="two">
<!--<a href="<?php echo $_SERVER["PHP_SELF"] ?>" name="submit">test </a>-->
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Re: Get Radio Button value using php $_GET
Posted: Sat Apr 23, 2011 12:57 pm
by Christopher
Yes, you need it to be a submit button. There is also the problem that if you submit a form with the Enter key in IE you don't get the submit field. A hidden field might be a good idea:
Code: Select all
<?PHP
if (isset($_GET["issubmitted"])) {
echo $_GET["myradio"];
}
?>
<html>
<head>
</head>
<body>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="get">
<input type="hidden" name="issubmitted" value="yes"/>
One <input type="radio" name="myradio" value="one"/>
Two <input type="radio" name="myradio" value="two"/>
<input type="submit" name="submitbutton" value="Submit"/></a>
</form>
</body>
</html>