Forum Moderators: coopster

Message Too Old, No Replies

PHP Radio Buttons Issue

         

MC SAS Master

5:17 pm on Jan 12, 2007 (gmt 0)

10+ Year Member



I'm hoping someone can help me out with an issue I'm having with another PHP form. The form I'm trying to create has a number of questions with three responses - Yes, No, and N/A. For some strange reason my form will not allow radio buttons to operate like they have in the past for me with PHP forms. For example, to get the form to work I have to give each Yes, No, and NA its own name in order for the "echo" command to work. Below is a snippet of the HTML and PHP code I'm using.

HTML
---------------------------------

<body>
<form action="ret.php" method="post">
<div align='center' div id="content">
</SCRIPT>
<p align="center">
<img border="0" src="logo.jpg">
</p>

<h2 align="center">Example Review Form</h2><br />

<table width='500' border='0' cellpadding='5'>
<br>
<form>
<table width='100%' border='0' align='center'>
<tr>
<td width='72%' bgcolor='#CCCCCC'><div align='left'>Section 1</div></td>
<td width='28%'>&nbsp;&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
No&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N/A</td>
</tr>
<tr>
<td><div align='left'></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<form>
<td><div align='left'>A. Entries legible </div></td>
<td><table width='95%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td><div align='center'>
<INPUT TYPE="radio" NAME='meca' VALUE="Yes">
</div></td>
<td><div align='center'>
<input type="radio" NAME='meca' VALUE="No">
</div></td>
<td><div align='center'>
<input type="radio" NAME='meca' VALUE="NA">
</div></td>
</tr>
</table></td>
</form>
</tr>

<tr>
<td><div align='left'>B. Entries signed </div></td>
<td><table width='95%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td><div align='center'>
<input type="radio" value="Yes" name="mecb">
</div></td>
<td><div align='center'>
<input type="radio" value="No" name="mecb">
</div></td>
<td><div align='center'>
<input type="radio" value="NA" name="mecb">
</div></td>
</tr>
</table></td>
</tr>
<tr>

<td><div align='left'>C. Entries dated </div></td>
<td><table width='95%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td><div align='center'>
<input type="radio" value="Yes" name="mecc">
</div></td>
<td><div align='center'>
<input type="radio" value="No" name="mecc">
</div></td>
<td><div align='center'>
<input type="radio" value="NA" name="mecc">
</div></td>
</tr>
</table></td>
</tr>
<tr>
<td><div align='left'></div></td>
<td>&nbsp;</td>
<p align='center'>
<input name='Process Form' type='submit' id='Click Here To Process Form' value='Process Form' />
</p>

</div>

<input type="hidden" name="meca" value="<? echo $_POST['meca']?>">
<input type="hidden" name="mecb" value="<? echo $_POST['mecb']?>">
<input type="hidden" name="mecc" value="<? echo $_POST['mecc']?>">
</form>
</body>
</html>

PHP
------------------------------
<body>

<div align='center' div id="content">
</SCRIPT>
<p align="center">
<img border="0" src="logo.jpg">
</p>

<h2 align="center">DRAFT Unity Health Care Peer Review Form</h2><br />
<table width='500' border='0' cellpadding='5'></table>
<?php
//<form action="output.php" method="post">
echo 'Entries legible: <b>'.$_POST['meca1'].''.$_POST['meca2'].''.$_POST['meca3'].'</b><br />';
echo 'Entries signed: <b>'.$_POST['mecb'].'</b><br />';
echo 'Entries dated: <b>'.$_POST['mecc'].'</b><br />';
?>

<input type="hidden" name="meca" value="<? echo $_POST['meca']?>">
<input type="hidden" name="mecb" value="<? echo $_POST['mecb']?>">
<input type="hidden" name="mecc" value="<? echo $_POST['mecc']?>">
</body>
</html>

barns101

6:02 pm on Jan 12, 2007 (gmt 0)

10+ Year Member



That code looks completely correct. Each of the three options ($_POST['meca'], $_POST['mecb'], $_POST['mecc']) needs its own name or it will be overwritten by the last selection when the form is submitted if all of the options were called $_POST['meca']

You can combine then into one variable after submission like this:


$answers = $_POST['meca'].$_POST['mecb'].$_POST['mecc'];

Hope that makes sense. :)

eelixduppy

8:52 pm on Jan 12, 2007 (gmt 0)



This is the problem line:

echo 'Entries legible: <b>'.$_POST['meca1'].''.$_POST['meca2'].''.$_POST['meca3'].'</b><br />';

$_POST['meca1'], $_POST['meca2'], $_POST['meca3'] all do not exist. I'm not sure what you are trying to do here otherwise I'd make a suggestion. But this is definitely the problem.

You can try escaping that line just to see how everything works at first.

And welcome to WebmasterWorld! :)

supermanjnk

9:29 pm on Jan 12, 2007 (gmt 0)

10+ Year Member



Another side note:

You also have multiple opening and closing form tags nested within other form tags.