using radio buttons in html and php...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joseph
Forum Newbie
Posts: 24
Joined: Mon Jul 03, 2006 6:15 am

using radio buttons in html and php...

Post by joseph »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


How do we declare variables if we have multiple radio buttons in html and would like to use it as a feedback form to send it thru the use of php codes?

If I have these codes in html:

Code: Select all

<form action="../php/feedback.php" method="post" name="frmFeedback" id="frmFeedback">
<table width="600" border="0" align="center" cellpadding="1" cellspacing="2" bgcolor="#F5F5F5" class="feedback">
<tr>
<td width="164"><span class="style17"></span></td>
<td width="436"><span class="style17">
<label>
<input name="title" type="radio" value="mr" checked></label>
Mr. 
<label>
<input name="title" type="radio" value="mrs">
</label>
Mrs. 
<label>
<input name="title" type="radio" value="ms">
</label>
Ms. </span></td></tr></table></form>
and the php codes:

Code: Select all

$title        = cleanUp($_POST['mr']);
$title        = cleanUp($_POST['mrs']);
$title        = cleanUp($_POST['ms']);

echo "<form action=\"feedback.php\" method=\"post\"><p>";
echo "<input type=\"radio\" name=\"title\" id=\"mr\" value=\"$title\" /> Mr<br />";
echo "<input type=\"radio\" name=\"title\" id=\"mrs\" value=\"$title\" /> Mrs<br />";
echo "<input type=\"radio\" name=\"title\" id=\"ms\" value=\"$title\" /> Ms<br />";

$message   = "Title: $title \n";
Is that how we declare or use the radio buttons? The use could only choose one from Mr Mrs and Ms. But it should also only send one title that is chosen when the user fills up the form. So ... is there something wrong with my declarations? Thanks.


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
noclss2000
Forum Newbie
Posts: 7
Joined: Thu Jun 22, 2006 11:11 am

Post by noclss2000 »

why not just use that as a dropdown for Mr./Mrs./Ms.?
It'll look a lot cleaner
joseph
Forum Newbie
Posts: 24
Joined: Mon Jul 03, 2006 6:15 am

Post by joseph »

noclss2000 wrote:why not just use that as a dropdown for Mr./Mrs./Ms.?
It'll look a lot cleaner
I don't know how to code for drop down menus too... could you please translate this one above a sample code in php? Thanks..
User avatar
technofreak
Forum Commoner
Posts: 74
Joined: Thu Jun 01, 2006 12:30 am
Location: Chennai, India
Contact:

Post by technofreak »

In order to use multiple radio buttons or check boxex use thier 'value' attribute and also use 'checked = "checked"'. When a user selects a radio button, then its 'value = 'assigned_val' becomes true and in such cases u can make 'checked ="checked"'. Remember to have common 'name' for the radio/check button group, so that only one radio button will be checked as well as remember to have atleast one button checked by default.
User avatar
technofreak
Forum Commoner
Posts: 74
Joined: Thu Jun 01, 2006 12:30 am
Location: Chennai, India
Contact:

Post by technofreak »

Here is the PHP code to print a drop down list of days of a month. Use the code to fit to your requirements :)

Code: Select all

for ($i = 1; $i <= 31; $i++) {
      print '<option value="' .$i. '">' .$i. "</option>\n";
}
Post Reply