PHP w/ multiple radio buttons...Help...
08-18-04, 03:46 PM
Newbie Coder
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
PHP w/ multiple radio buttons...Help...
I am very new to PHP. I'm trying to create a survey form & have it save the fields to PHP. Could someone please look at my file & see what I am doing wrong? I can't the radio buttons to work right.
Please see attached file.
Thanks!
Eddie
08-18-04, 09:58 PM
Wannabe Coder
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
Can you show us a demo URL? To see what the problem is? Or tell us at least what the problem is?
Kevin
08-19-04, 04:52 AM
Newbie Coder
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
In all the buttonsets you have:
While you probably should have:
In short: no matter what button is selected in your code, it's value is always 1.
08-19-04, 12:14 PM
Newbie Coder
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Problem..
Here's what is happening. I have created a form that has radio buttons:
I.E.
How was your stay here: O O O O O
Was everything ok: O O O O O
After everything is filled in, the user will click submit & the data will be in PHP. Please see the code. It is not saving any of the buttons.
Please see link for example:
http://www.alphausa.com/survey/index.htm
Thanks!
08-19-04, 01:49 PM
Newbie Coder
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
If you are a newbie, start with smaller problems -- create very simple form with handling and once you get it to work apply the working technique on bigger problem. I guess there aren't many who bother to read very long codes especially if the actual problem is quite basic stuff. At least I don't anymore
08-19-04, 01:55 PM
Newbie Coder
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not asking for the whole form to be fixed. I'm just wondering if anyone knows how to use multiple radio buttons on the page with one submit button? I want to pass the value to PHP for each radio button & I can handle it from there.
08-19-04, 02:18 PM
Newbie Coder
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Here it is in it's simplest form. Assuming the following is the contents of the file 'index.php'. Any help?
09-15-04, 12:49 PM
Newbie Coder
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by darkfreak
Here it is in it's simplest form. Assuming the following is the contents of the file 'index.php'. Any help?
Ok, I finally got my code to work. Now I have one last question to ask. When a button is not selected, I want a message sent stating the field needs to be filled out. Please see my code. If the buttons aren't selected, it just loops back to a blank page. Any idea why it's not working?
PHP Code:
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Alpha Stamping Customer Survey</title>
</head>
<body style="text-align: left">
<? function show_form ( $R1 = "" , $R2 = "" , $R3 = "" , $R4 = "" , $R5 = "" , $R6 = "" , $R7 = "" ) { ?>
<div align="center">
<table border="0" style="border-collapse: collapse" width="76%" id="table1" height="877">
<tr>
<td valign="top">
<table border="0" style="border-collapse: collapse" width="100%" id="table3" height="81">
<tr>
<td width="538">
<p align="left">
<img border="0" src="tag_logo.gif" width="270" height="61"></td>
<td width="203">
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>
<font size="4" face="Courier New"> Customer Survey</font></b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="4"><b> </b></font><b>
<font face="Courier New" size="4">Plant Visit</font></b></td>
</tr>
</table>
<table border="0" style="border-collapse: collapse" width="100%" id="table35">
<tr>
<td width="359"> </td>
<td width="199"><b>Date of visit: 8/05/04</b></td>
<td><b>Facility: Alpha Stamping</b></td>
</tr>
</table>
<p style="margin-left: 20px; margin-right: 20px">Thank you for visiting our facility. Our goal is to provide
the best experience possible to our guests.</p>
<p style="margin-left: 20px; margin-right: 20px">Help us provide an optimal experience for future visitors.
Please complete the following survey and return it in the enclosed
envelope. Please answer these questions about your visit using
the following scale:</p>
<div align="center">
<table border="0" style="border-collapse: collapse" width="92%" id="table4">
<tr>
<td width="140">
<p align="center">
<img border="0" src="tag_bt_1.gif" width="25" height="22"></td>
<td width="140">
<p align="center">
<img border="0" src="tag_bt_2.gif" width="25" height="22"></td>
<td width="140">
<p align="center">
<img border="0" src="tag_bt_3.gif" width="25" height="22"></td>
<td width="140">
<p align="center">
<img border="0" src="tag_bt_4.gif" width="25" height="22"></td>
<td width="140">
<p align="center">
<img border="0" src="tag_bt_5.gif" width="25" height="22"></td>
</tr>
<tr>
<td width="140">
<p align="center"><b>Strongly Disagree</b></td>
<td width="146">
<p align="center"><b>Disagree</b></td>
<td width="133">
<p align="center"><b>Neutral</b></td>
<td>
<p align="center"><b>Agree</b></td>
<td width="143">
<p align="center"><b>Strongly Agree</b></td>
</tr>
</table>
<p align="center" style="margin-top: 0; margin-bottom: 0"> </p>
<table border="1" style="border-collapse: collapse" width="98%" id="table5" background="tag_hdr_red.gif">
<tr>
<td>
<table border="0" style="border-collapse: collapse" width="100%" id="table6">
<tr>
<td width="265"> </td>
<td width="171"><b>Choose ONE Only</b></td>
<td>
<p align="center"><b>Please Comment</b></td>
</tr>
</table>
</td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="98%" id="table7" height="45">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
1. Upon arrival, I was greeted in a courteous and
professional manner.</td>
<td width="178" valign="top">
<table border="0" style="border-collapse: collapse" width="90%" id="table30" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<form action="index.htm" method="get">
<input type="radio" value=1 name="R1"></td>
<td width="26">
<input type="radio" value=2 name="R1"></td>
<td width="26">
<input type="radio" value=3 name="R1"></td>
<td width="26">
<input type="radio" value=4 name="R1"></td>
<td>
<input type="radio" value=5 name="R1"></td>
</tr>
</table>
</td>
<td valign="top">
<textarea rows="2" name="S1" cols="32"></textarea></td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="98%" id="table10" cellpadding="0">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
2. During my visit, I was treated in a courteous
and professional manner.</td>
<td width="182" valign="top">
<table border="0" style="border-collapse: collapse" width="90%" id="table29" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<input type="radio" value=1 name="R2"></td>
<td width="26">
<input type="radio" value=2 name="R2"></td>
<td width="26">
<input type="radio" value=3 name="R2"></td>
<td width="26">
<input type="radio" value=4 name="R2"></td>
<td>
<input type="radio" value=5 name="R2"></td>
</tr>
</table>
</td>
<td valign="top">
<textarea rows="2" name="S2" cols="32"></textarea></td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="98%" id="table13" cellpadding="0">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
3. I received answers to all my questions during
my visit.</td>
<td width="182" valign="top">
<table border="0" style="border-collapse: collapse" width="90%" id="table28" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<input type="radio" value="1" name="R3"></td>
<td width="26">
<input type="radio" value="2" name="R3"></td>
<td width="26">
<input type="radio" value="3" name="R3"></td>
<td width="26">
<input type="radio" value="4" name="R3"></td>
<td>
<input type="radio" value="5" name="R3"></td>
</tr>
</table>
</td>
<td valign="top">
<textarea rows="2" name="S3" cols="32"></textarea></td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="98%" id="table16" cellpadding="0">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
4. I was shown all aspects of the operation I
wanted to see.</td>
<td width="182" valign="top">
<table border="0" style="border-collapse: collapse" width="90%" id="table27" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<input type="radio" value="1" name="R4"></td>
<td width="26">
<input type="radio" value="2" name="R4"></td>
<td width="26">
<input type="radio" value="3" name="R4"></td>
<td width="26">
<input type="radio" value="4" name="R4"></td>
<td>
<input type="radio" value="5" name="R4"></td>
</tr>
</table>
</td>
<td valign="top">
<textarea rows="2" name="S4" cols="32"></textarea></td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="98%" id="table19" cellpadding="0">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
5. The facility was pleasant to visit and well
maintained.</td>
<td width="182" valign="top">
<table border="0" style="border-collapse: collapse" width="90%" id="table26" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<input type="radio" value="1" name="R5"></td>
<td width="26">
<input type="radio" value="2" name="R5"></td>
<td width="26">
<input type="radio" value="3" name="R5"></td>
<td width="26">
<input type="radio" value="4" name="R5"></td>
<td>
<input type="radio" value="5" name="R5"></td>
</tr>
</table>
</td>
<td valign="top">
<textarea rows="2" name="S5" cols="32"></textarea></td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="98%" id="table22" cellpadding="0">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
6. I was offered eye and hearing protection before
entering the production floor.</td>
<td width="182" valign="top">
<p style="margin-top: -13px; margin-bottom: 0"> </p>
<table border="0" style="border-collapse: collapse" width="90%" id="table25" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<input type="radio" value="1" name="R6"></td>
<td width="26">
<input type="radio" value="2" name="R6"></td>
<td width="26">
<input type="radio" value="3" name="R6"></td>
<td width="26">
<input type="radio" value="4" name="R6"></td>
<td>
<input type="radio" value="5" name="R6"></td>
</tr>
</table>
</td>
<td valign="top"><textarea rows="2" name="S6" cols="32"></textarea></td>
</tr>
</table>
<p style="margin-top: 0; margin-bottom: 0"> <table border="0" style="border-collapse: collapse" width="98%" id="table33" cellpadding="0" height="64">
<tr>
<td width="268" valign="top">
<p align="left" style="margin-left: 11px; margin-right: 11px">
7. I was completely satisfied by my visit.</td>
<td width="182" valign="top">
<table border="0" style="border-collapse: collapse" width="90%" id="table34" cellpadding="0">
<tr>
<td width="26" height="24">
<img border="0" src="tag_bt_1.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_2.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_3.gif" width="21" height="18"></td>
<td width="26" height="24">
<img border="0" src="tag_bt_4.gif" width="21" height="18"></td>
<td height="24">
<img border="0" src="tag_bt_5.gif" width="21" height="18"></td>
</tr>
<tr>
<td width="26">
<input type="radio" value="1" name="R7"></td>
<td width="26">
<input type="radio" value="2" name="R7"></td>
<td width="26">
<input type="radio" value="3" name="R7"></td>
<td width="26">
<input type="radio" value="4" name="R7"></td>
<td>
<input type="radio" value="5" name="R7"></td>
</tr>
</table>
</td>
<td valign="top"><textarea rows="2" name="S7" cols="32"></textarea></td>
</tr>
</table>
<table border="0" style="border-collapse: collapse" width="100%" id="table36" height="90">
<tr>
<td colspan="2">
<div align="center">
<table border="1" style="border-collapse: collapse" width="98%" id="table39" background="tag_hdr_red.gif">
<tr>
<td>
<div align="center">
<table border="0" style="border-collapse: collapse" width="100%" id="table40">
<tr>
<td>
<p align="center"><b>Thank you for your time!
Please click the "Submit Survey" button.</b></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td height="63" width="80%">
<p align="center"> </td>
<td width="19%" height="63">
<input type="submit" value="Submit Survey""></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</form>
<?php }
if (!isset( $_GET [ 'R1' ]) or !isset( $_GET [ 'R2' ]) or !isset( $_GET [ 'R3' ])
or !isset( $_GET [ 'R4' ]) or !isset( $_GET [ 'R5' ]) or !isset( $_GET [ 'R6' ])
or !isset( $_GET [ 'R7' ])) {
show_form ();
}
else {
$R1 = $_GET [ 'R1' ];
$R2 = $_GET [ 'R2' ];
$R3 = $_GET [ 'R3' ];
$R4 = $_GET [ 'R4' ];
$R5 = $_GET [ 'R5' ];
$R6 = $_GET [ 'R6' ];
$R7 = $_GET [ 'R7' ];
if (empty( $R1 ) or empty( $R2 ) or empty( $R3 ) or empty( $R4 ) or empty( $R5 ) or empty( $R6 ) or
empty( $R7 )) {
echo "<H2>There is a Problem:</H2>" ;
echo "<H4>Please fill in your " ;
$PrevError = "" ;
if (empty( $R1 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 1" ;
$PrevError = "Y" ;
}
if (empty( $R2 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 2" ;
$PrevError = "Y" ;
}
if (empty( $R3 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 3" ;
$PrevError = "Y" ;
}
if (empty( $R4 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 4" ;
$PrevError = "Y" ;
}
if (empty( $R5 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 5" ;
$PrevError = "Y" ;
}
if (empty( $R6 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 6" ;
$PrevError = "Y" ;
}
if (empty( $R7 )) {
If ( $PrevError == "Y" ) { echo ", " ; }
echo "Question 7" ;
$PrevError = "Y" ;
}
echo ".</H4>" ;
show_form ( $R1 , $R2 , $R3 , $R4 , $R5 , $R6 , $R7 ); }}
if ( isset( $_GET [ 'R1' ]) and isset( $_GET [ 'R2' ]) ) {
echo "Testing selected values:<br><br>" ;
echo "Question 1: $R1 <br>" ;
echo "Question 1 Comments: $S1 <br><br>" ;
echo "Question 2: $R2 <br>" ;
echo "Question 2 Comments: $S2 <br><br>" ;
echo "Question 3: $R3 <br>" ;
echo "Question 3 Comments: $S3 <br><br>" ;
echo "Question 4: $R4 <br>" ;
echo "Question 4 Comments: $S4 <br><br>" ;
echo "Question 5: $R5 <br>" ;
echo "Question 5 Comments: $S5 <br><br>" ;
echo "Question 6: $R6 <br>" ;
echo "Question 6 Comments: $S6 <br><br>" ;
echo "Question 7: $R7 <br>" ;
echo "Question 7 Comments: $S7 <br><br>" ;
echo "<a href=\"index.htm\">Return to blank survey form</a>" ;
die;
}
?>
</body>
</html>
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off