wrong radio button selected after error occurs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maciek4
Forum Commoner
Posts: 29
Joined: Tue Apr 04, 2006 8:17 am

wrong radio button selected after error occurs

Post 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>
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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.
maciek4
Forum Commoner
Posts: 29
Joined: Tue Apr 04, 2006 8:17 am

Post by maciek4 »

Perfect. Worked just like I wanted it to. Thx
Post Reply