Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

please help ;

By default, form elements will be accessed through the $_GET array. We want to access the form elements using the $_POST array, like this: $_POST["flavor"]. Make the change to the HTML that will allow the process.php script to access the $_POST array. (Hint: we need to add a new attribute to an existing HTML element.) Important: In each task of this code challenge, the code you write should be added to the code from the previous task. Preview Get Help Reset Code Check Work index.html

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Ye Olde Ice Cream Shoppe</title> 5 </head> 6 <body> 7 ​ 8 <p>Your order has been created. What flavor of ice cream would you like to add to it?</p> 9 ​ 10 <form action="process.php"> 11 ​ 12 <label for="flavor">Flavor</label> 13 <select id="flavor"> 14 <option value="">— Select —</option> 15 <option value="Vanilla">Vanilla</option> 16 <option value="Chocolate">Chocolate</option> 17 <option value="Strawberry">Strawberry</option> 18 <option value="Cookie Dough">Cookie Dough</option> 19 </select> 20 ​ 21 <input type="submit" value="Update Order"> 22 ​ 23 </form> 24 ​ 25 </body> 26 </html>

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 action="process.php">

        <label for="flavor">Flavor</label>
        <select id="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>

2 Answers

Simon Coates
Simon Coates
28,694 Points

add method attribute of post to the form element.

update: for anyone in the future, if the reason why the change works isn't clear, Evelyn's answer explains the issue a little. If needing more, google "superglobals".

thank's simon:)

By default, form elements will be accessed through the $_GET array. We want to access the form elements using the $_POST array, like this: $_POST["flavor"]. Make the change to the HTML that will allow the process.php script to access the $_POST array. (Hint: we need to add a new attribute to an existing HTML element.)