3
votes

I currently have the following code, which I will implement functionality for later in a separate .php file:

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Radio Input Testing</title>
    </head>
    <body>
        <form action="" method="post">
            <h3>Sign up now!</h3>
            <br>

            Name: <input type="text" name="name"><br>
            Select from one of the following:<br>
            <input type="radio" name="food" value="pasta">Pasta</input><br>
            <input type="radio" name="food" value="salad">Salad </input><br>
            <input type="radio" name="food" value="pizza">Pizza</input><br>
            <input type="radio" name="food" value="hotdogs">Hotdogs</input>           
            <br>
            <input type="radio" name="food" value="burgers">Burgers</input>         
            <br>
            <br>
            <input type="submit" value="Submit">
        </form>
    </body>
    </html>

What I want to do is have each person signing up input their name, select an option to sign up for, and upon submitting the form, see their name next to the option, with the selection for the radio input gone.

For example, if "Sarah" picks the Pasta option, this should happen upon submitting the form:

    Pasta - Sarah // No radio selection
    // Other options that can be selected from

I know that I'd have to submit the form to itself, but I don't know how to change the status of the button through PHP. Any help is appreciated!

1

1 Answers

2
votes

Add a fieldgroup wrapper to those inputs and then check if the form was submit, and if it was, hide them with CSS.

<fieldgroup <?php echo isset($_POST['food']) ? 'style="display:none;"' : '' ?>>
    ....inputs
</fieldgroup>

Of course, echo $_POST['name'] . ' - ' . $_POST['food'] to get the print of what you want.