/    Sign up×
Community /Pin to ProfileBookmark

radio buttons in php? help!

I have 2 simple forms, how can i pass radio button data (into a hidden field) from one form to the other using php?

below is how I am achieving it with text fields but php deals with radio buttons differently apparently?

[code=php]

<form action=”mortgages3_s.php” method=”post” name=”mm”>

<input type=”hidden” name=”singleFullNametwo” value=”<?php_echo_$_POST[‘singleFullName’];?>”>
<input type=”hidden” name=”singleDateofBirthtwo” value=”<?php_echo_$_POST[‘singleDateofBirth’];?>”>
<input type=”text” name=”hair”>

<input type=”submit”>

[/code]

thanks

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 17.2003 — Yep, you can reference radio buttons the same way, as can be seen in this simple test:

[code=php]<?PHP

if (isset($_POST["submit"])) {
echo $_POST["myradio"];
}

?>

<html>
<head>
</head>
<body>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post">
One <input type="radio" name="myradio" value="one">
Two <input type="radio" name="myradio" value="two">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@YanheadauthorJun 17.2003 — what would PHP pass if I submitted this?

[code=php]

<form_action="page2.php"_method="post"_name="radioform">
<input_type="radio"_name="radiogroup"_value="yes"><input_type="radio"_name="radiogroup"_value="no">

________</form>

[/code]


thanks
Copy linkTweet thisAlerts:
@pyroJun 17.2003 — Depending on which one is checked, it would return "yes" or "no" when you access it like this on page2.php:

$_POST["radiogroup"];

This is also assumbing you change the understrikes to spaces
Copy linkTweet thisAlerts:
@IncendionJul 11.2006 — What if you have more than two options that you want to be able to be selected, i have at least 4 choices that i need in one radio button set, how would that be done?
Copy linkTweet thisAlerts:
@aussie_girlJul 12.2006 — What if you have more than two options that you want to be able to be selected, i have at least 4 choices that i need in one radio button set, how would that be done?[/QUOTE]

you will have to use check boxes, radio buttons are only two values, yes/no, true/false, on/off, m/f understand?
Copy linkTweet thisAlerts:
@RogueDoggJul 12.2006 — What's the deal with all the " _ "/s Doesn't that mess up your code?
Copy linkTweet thisAlerts:
@aussie_girlJul 13.2006 — What's the deal with all the " _ "/s Doesn't that mess up your code?[/QUOTE]
I's not code..it's just a statement to say that radio buttons are only for two values.. either yes or no etc.. If you need to have more than one option checked use check boxes or lists
Copy linkTweet thisAlerts:
@RogueDoggJul 13.2006 — I's not code..it's just a statement to say that radio buttons are only for two values.. either yes or no etc.. If you need to have more than one option checked use check boxes or lists[/QUOTE]

Huh?

<form_action="page2.php"_method="post"_name="radioform">

<input_type="radio"_name="radiogroup"_value="yes"><input_type="radio"_name="radiogroup"_value="no">

________</form>[/QUOTE]


This above with the _ 's is ok? I wouldn't think it would be? ?
Copy linkTweet thisAlerts:
@aussie_girlJul 13.2006 — Sorry RogueDogg I thought you were talking about my message and Pyro has already answered that question about the under scores above
Copy linkTweet thisAlerts:
@rainstinksFeb 12.2010 — So, would you just use two different sets of radio button input tags, if you were using four radio button, and just check to see which one is set? And then carry out whatever action you need/want done from there?

My teacher wants us to create a form where users enters 2 numbers and then clicks one of four radio buttons (add/subtract/multiply/divide). Then when they click the submit button, the user is transferred to the results page where their two numbers are either added, subtracted, multiplied, or divided depending on which radio button. All I'm getting is a blank page for the results, which is why I ask.
Copy linkTweet thisAlerts:
@SrWebDeveloperFeb 12.2010 — Use 1 group of 4 radio buttons - this makes the user choose [B]only one[/B] of the 4, that's why radio buttons exist compared to checkboxes which is [B]one or more[/B]. You could also use select (without the "multiple" attribute) but the radio button is more intuitive.

Syntax and usage documented here.


As to errors, post your code (the form and the script that processes the results) and we'll help you debug.
Copy linkTweet thisAlerts:
@rainstinksFeb 17.2010 — Alright, here is the code I have for the time being for the two pages:

Form Page:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>

2910_22.php

</title>

</head>

<body>

<!--author:shane nelson-->

<form method="post" action="2910_22_get.php" name="form1">

Enter #1: <input type="text" name="num1" /> <br />

Enter #2: <input type="text" name="num2" /> <br />

<input type="radio" name="add" value="add" />Addition <br /> <!--purpose: add-->

<input type="radio" name="add" value="sub" />Subtraction <br /> <!--purpose: sub-->

<input type="radio" name="add" value="mult" />Multiplication <br /> <!--purpose:mult-->

<input type="radio" name="add" value="div" />Division <br /> <!--purpose:div-->

<input type="submit" value="submit" />

</form>

</body>

</html>

Results Page:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>

2910_22_get.php

</title>

</head>

<body>

<!--author:shane nelson-->

<?php

$num1=$_POST['num1'];

$num2=$_
POST['num2'];

$radio=$_POST['add'];

if ($radio == add)

{

$y=$num1 + $num2;

echo $num1." + ".$num2." = ".$y;

}

elseif ($radio == sub)

{

$y=$num1 - $num2;

echo $num1." - "$num2." = ".$y;

}

elseif ($radio == mult)

{

$y=$num1 * $num2;

echo $num1." X ".$num2." = ".$y;

}

else

{

$y=$num1 / $num2;

echo $num1." / ".$num2." = ".$y;

}

?>

</body>

</html>

That's what I had last week, I haven't worked on this particular assignment recently. The form page works fine, but no matter what you put into the fields, you receive a blank page at the results page. This, I assume, has something to do with the radio buttons not working right in the code in the results page. Any help would be greatly appreciated.

Oh, here's a link to the form page, if you want to see what it does when you try to input and submit:

http://ito.auburncc.org/localuser/snelson/month_2_of_10/2910_22.php
×

Success!

Help @Yanhead spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...