Page 1 of 1

wrong radio button selected after error occurs

Posted: Thu Nov 30, 2006 3:29 am
by maciek4
I have a survey and one of the questions has radio buttons in it. If I dont fill in all the required fields an error message occurs and the last radio button is selected. So if someone selects lets say A and submits but an error message occurs then the button selected switches to E. I would like it to remain the same as it was selected.

Here is the code:

Code: Select all

<INPUT TYPE="radio" NAME="progress" value="A" <?echo isset($progress['A']) ? 'checked' : ''; ?>>&nbsp;A - very big<br>
<INPUT TYPE="radio" NAME="progress" value="B" <?echo isset($progress['B']) ? 'checked' : ''; ?>>&nbsp;B - big<br>
<INPUT TYPE="radio" NAME="progress" value="C" <? echo isset($progress['C']) ? 'checked' : ''; ?>>&nbsp;C - medium<br>
<INPUT TYPE="radio" NAME="progress" value="D" <? echo isset($progress['D']) ? 'checked' : ''; ?>>&nbsp;D - small<br>
<INPUT TYPE="radio" NAME="progress" value="E" <? echo isset($progress['E']) ? 'checked' : ''; ?>>&nbsp;E - very small<br>

Posted: Thu Nov 30, 2006 4:11 am
by dibyendrah
you have to change

Code: Select all

<?echo isset($progress['A']) ? 'checked' : ''; ?>
to

Code: Select all

<?php
print (isset($_POST[progress]) && $_POST[progress]=='A')  ? 'checked' : ''; 
?>
Also, change code like above for other radio buttons.

Posted: Thu Nov 30, 2006 4:26 am
by maciek4
Perfect. Worked just like I wanted it to. Thx