Page 1 of 1

using radio buttons in html and php...

Posted: Mon Jul 03, 2006 9:59 am
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]

Posted: Mon Jul 03, 2006 11:04 am
by noclss2000
why not just use that as a dropdown for Mr./Mrs./Ms.?
It'll look a lot cleaner

Posted: Mon Jul 03, 2006 10:00 pm
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..

Posted: Mon Jul 03, 2006 11:18 pm
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.

Posted: Mon Jul 03, 2006 11:25 pm
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";
}