How can a PHP form be structured to redirect users to specific pages based on their radio button selection?

To redirect users to specific pages based on their radio button selection in a PHP form, you can use a conditional statement to check the value of the selected radio button and then redirect the user accordingly using the header() function.

<?php
if(isset($_POST['submit'])){
    $selection = $_POST['selection'];
    
    if($selection == 'option1'){
        header("Location: page1.php");
        exit();
    } elseif($selection == 'option2'){
        header("Location: page2.php");
        exit();
    } elseif($selection == 'option3'){
        header("Location: page3.php");
        exit();
    } else {
        echo "Invalid selection";
    }
}
?>

<form method="post" action="">
    <input type="radio" name="selection" value="option1"> Option 1 <br>
    <input type="radio" name="selection" value="option2"> Option 2 <br>
    <input type="radio" name="selection" value="option3"> Option 3 <br>
    <input type="submit" name="submit" value="Submit">
</form>