Reputation: 8086
Ok so I got a form and usability is important to me. If the user completes the form and then hits submit but there are errors on the form I have set values to echo back
e.g.
<input class="input_phone" name="phone" type="text" value="<?php echo $_POST['phone']; ?>" maxlength="15" />
The value entered will be back in the form field so that the user doesn't have to retype every field.
How do i achieve the same effect with radio buttons?
<input class="radio" name="q1" type="radio" value="YES">
If i set the value to $_POST['q1']
How do I set it to YES
?
Upvotes: 0
Views: 110
Reputation: 13956
if isset($_POST['q1']){
echo '<input class="radio" name="q1" type="radio" checked="checked" value="YES">';
}else{
echo '<input class="radio" name="q1" type="radio" value="NO">';
}
Upvotes: 1
Reputation: 160833
It is same with input text, just with attribute checked
.
<input class="radio" name="q1" type="radio" value="YES" <?php echo $_POST['q1'] === 'YES' ? 'checked' : ''; ?>>
Upvotes: 2