I am having a real problem with this and I can't figure it out. I am not that much of a techie so take it easy on me.
I am building a survey form for a website to get feedback on the service, and naturally it can fail validation if the email address is misspelled or the security question is answered wrong. Retaining text values was easy and I managed to dig around for some solutions to retain radio button values. The problem is IT SEEMS TO ONLY WORK ON ONE OPTION!
I tried everything including coming up with a diferent value name for each question, yet the page still loads with all radio options set to the same shared value (usually of the last radio button question), i.e. If I select Very good for the first question, and satisfactory for the second, and weak for the third, and I click submit but the page fails validation, when the page reloads, all the questions seem to be answered at "weak".
Here is my code:
<?php
}
}
if(!isset($_POST['send']) || $error != '')
{
?>
<?PHP
$Excellent_status = 'unchecked';
$VeryGood_status = 'unchecked';
$Satisfactory_status = 'unchecked';
$Weak_status = 'unchecked';
$Horrible_status = 'unchecked';
if (isset($_POST['send']))
{
$selected_tk = $_POST['tk'];
if ($selected_tk == 'Excellent') {
$Excellent_status = 'checked';
}
else if ($selected_tk == 'VeryGood') {
$VeryGood_status = 'checked';
}
else if ($selected_tk == 'Satisfactory') {
$Satisfactory_status = 'checked';
}
else if ($selected_tk == 'Weak') {
$Weak_status = 'checked';
}
else if ($selected_tk == 'Horrible') {
$Horrible_status = 'checked';
}
}
$Excellent2_status = 'unchecked';
$VeryGood2_status = 'unchecked';
$Satisfactory2_status = 'unchecked';
$Weak2_status = 'unchecked';
$Horrible2_status = 'unchecked';
if (isset($_POST['send']))
{
$selected_ts = $_POST['ts'];
if ($selected_ts == 'Excellent') {
$Excellent2_status = 'checked';
}
else if ($selected_ts == 'VeryGood') {
$VeryGood2_status = 'checked';
}
else if ($selected_ts == 'Satisfactory') {
$Satisfactory2_status = 'checked';
}
else if ($selected_ts == 'Weak') {
$Weak2_status = 'checked';
}
else if ($selected_ts == 'Horrible') {
$Horrible2_status = 'checked';
}
}
?>
<h1 align="center">Feedback Form:</h1>
<p align="center">We highly value your input. Your feedback can help us serve you better and provide you with a holistic experience that meets or exceeds all your expectations. <br />
Please take the time to fill out the form below.</p>
<br />
<br />
<p align="center"><strong>(Fields marked with a <span class="required">*</span> are necessary. The course information is to validate which course and batch the survey is regarding, and the name and email allows our admin to verify the details and gain more information from you if needed)</strong></p>
<p align="center"><strong>The identity in this form is strictly confidential, and it will not be revealed to course trainer, co-ordinator, or your sponsor.</strong></p>
<!--Error Message-->
<?php echo $error;?>
<form method="post" name="contFrm" id="contFrm" action="">
<label><span class="required">*</span>Name:</label>
<input name="name" type="text" class="box" id="name" size="40" value="<?php echo $name;?>" /><br />
<label><span class="required">*</span>Email: </label>
<input name="email" type="text" class="box" id="email" size="40" value="<?php echo $email;?>" /><br />
<label><span class="required">*</span>Course attended: </label>
<input name="course" type="text" class="box" id="course" size="40" value="<?php echo $course;?>" /><br />
<label><span class="required">*</span>Course Date and City: </label>
<input name="dateplace" type="text" class="box" id="dateplace" size="40" value="<?php echo $dateplace;?>" /><br /><br /><br />
<table width="980" border="1" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="280" align="left" bgcolor="#285A80"><strong><font color="#FFFFFF" size="+1">Attribute</font></strong></td>
<td width="115">
<div align="center">EXCELLENT!
</div></td>
<td width="115">
<div align="center">Really Good.
</div></td>
<td width="115">
<div align="center">Satisfactory.
</div></td>
<td width="115">
<div align="center">Weak, needs attention.
</div></td>
<td width="115">
<div align="center">Horrible! Unacceptable.
</div></td>
</tr>
<tr>
<td width="280" align="left" bgcolor="#71C4CD"><strong><font color="#333333">Trainer Knowledge</font></strong></td>
<td>
<div align="center">
<input type="radio" name="tk" id="Excellent" value="Excellent" <?PHP print $Excellent_status; ?>/>
</div>
</td>
<td>
<div align="center">
<input type="radio" name="tk" id="VeryGood" value="VeryGood" <?PHP print $VeryGood_status; ?>/>
</div>
</label></td>
<td>
<div align="center">
<input type="radio" name="tk" id="Satisfactory" value="Satisfactory" <?PHP print $Satisfactory_status; ?>/>
</div>
</td>
<td>
<div align="center">
<input type="radio" name="tk" id="Weak" value="Weak" <?PHP print $Weak_status; ?>/>
</div>
</td>
<td>
<div align="center">
<input type="radio" name="tk" id="Horrible" value="Horrible" <?PHP print $Horrible_status; ?>/>
</div>
</td>
</tr>
<tr>
<td width="280" align="left" bgcolor="#71C4CD"><strong><font color="#333333">Trainer Style and Presentation</font></strong></td>
<td>
<div align="center">
<input type="radio" name="ts" id="Excellent2" value="Excellent2" <?PHP print $Excellent2_status; ?>/>
</div>
</td>
<td>
<div align="center">
<input type="radio" name="ts" id="VeryGood2" value="VeryGood2" <?PHP print $VeryGood2_status; ?>/>
</div>
</label></td>
<td>
<div align="center">
<input type="radio" name="ts" id="Satisfactory2" value="Satisfactory2" <?PHP print $Satisfactory2_status; ?>/>
</div>
</td>
<td>
<div align="center">
<input type="radio" name="ts" id="Weak2" value="Weak2" <?PHP print $Weak2_status; ?>/>
</div>
</td>
<td>
<div align="center">
<input type="radio" name="ts" id="Horrible2" value="Horrible2" <?PHP print $Horrible2_status; ?>/>
</div>
</td>
</tr>
</table>
<br /><br />
<label>Particularly positive points you appreciated: </label>
<textarea name="message1" cols="80" rows="3" id="message1"><?php echo $message1;?>
</textarea><br />
<label>Particularly negative points you found disappointing: </label>
<textarea name="message2" cols="80" rows="3" id="message2"><?php echo $message2;?>
</textarea><br />
<label>Any specific message you would like to provide us: </label>
<textarea name="message3" cols="80" rows="3" id="message3"><?php echo $message3;?>
</textarea><br />
<label><span class="required">* Security Question</span></label><? require_once ("ClassMathGuard.php"); MathGuard::insertQuestion(); ?>
<br />
<br />
<!-- Submit Button-->
<input name="send" type="submit" class="button" id="send" value="" />
</form>
Fact is there are 8 questions (all multiple choice with radio button answers) but I decided to save you a long code read.
What is wrong here? This really frustrated me.