PHP Build a Basic PHP Website (2018) Adding a Basic Form HTML Forms

Build A Basic PHP Website > Adding a Basic Form > HTML Forms

I'm not quite sure what to do with Question 4 on this code challenge.

Here's my code.

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Ye Olde Ice Cream Shoppe</title>
</head>
<body>

    <p>Your order has been created. What flavor of ice cream would you like to add to it?</p>

    <form method="post" action="process.php">

        <label for="flavor">Flavor</label>
        <select id="flavor" name="flavor">
            <option value="">&#8212; Select &#8212;</option>
            <option value="Vanilla">Vanilla</option>
            <option value="Chocolate">Chocolate</option>
            <option value="Strawberry">Strawberry</option>
            <option value="Cookie Dough">Cookie Dough</option>
        </select>

        <input type="submit" value="Update Order">

    </form>

</body>
</html>

The first step is looking for a form that will populate the $_GET global array. The following step will require that you populate the global $_POST array. (Hint: look at the attributes on the form).

Ben Payne:

Here's what I did: <input type ="hidden" name="order_id" value=7546>. I placed it above the other <input> tag. It passed. However, the instructor didn't cover the "hidden" attribute in her videos in this module. That was the tricky part. The value is an integer & not a string.

2 Answers

<option value="$_POST[flavor]">— Select —</option> :)

Stanimir Petkov:

See the answer I used. I don't think your answer quite answers the code challenge question as there are 3 attributes to be added to a new HTML element. I think your answer should appear as follows: <option value="$_POST["flavor"]"></option>. You don't need 2 "Selects" in the code as that is the "title" of the drop down menu of flavors. (Remember DRY, Don't Repeat Yourself, in code.) The "&#8212" is an "em dash," which is a special character of 2 dashes on either side of the word "Select" in the drop down menu, like so: "--Select--". I had to look up that special character definition.

This is another case where a question is asked that covers material that is not covered in the lesson. I'm posting here because someone else might run across the same issue.

The element to add is a hidden element:

<input type="hidden" id="order_id" name="order_id" value="7546">