Saving the Selected Value in Radio Buttons After Submission in PHP
Let's write code that will save the selected radio button after form submission:
<form action="" method="GET">
<input type="radio" name="radio" value="1" <?php
if (!empty($_GET['radio']) and $_GET['radio'] === '1') {
echo 'checked';
}
?>>
<input type="radio" name="radio" value="2" <?php
if (!empty($_GET['radio']) and $_GET['radio'] === '2') {
echo 'checked';
}
?>>
<input type="radio" name="radio" value="3" <?php
if (!empty($_GET['radio']) and $_GET['radio'] === '3') {
echo 'checked';
}
?>>
<input type="submit">
</form>
Using radio buttons, ask the user to select their language. Make sure the selection does not disappear after form submission.