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 Simple PHP Application Integrating with PayPal HTML Forms

Christopher Marshall Dyer
Christopher Marshall Dyer
9,760 Points

Help! Lost on the second step of the code challenge!

Not sure where to begin here, can anyone help?

form.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>
Christopher Marshall Dyer
Christopher Marshall Dyer
9,760 Points

This is the challenge:

Next, we need the flavor selected in the dropdown to be submitted to this process.php file. We need to be able to access it in the β€œflavor” element of the $_POST array, like this: $_POST["flavor"]. What two changes do we need to make to the HTML? (Hint. We need to add two new attributes. The first needs to be added to one existing HTML element, the second needs to be added to a different existing HTML element.)

3 Answers

Erik McClintock
Erik McClintock
45,783 Points

Christopher,

For this challenge, we need to recall what all is required on various elements in order to gain access to them from the back-end upon form submission. In the first task of the challenge, you added one missing component to your form element, the "action" attribute, which tells us WHERE the processing script is going to be. But we haven't told the script HOW to process (i.e. with what method we want to process).

The second task is letting you know that you will need to access the select element via PHP's $_POST array. How do we achieve this?

Perhaps if you recall that there are two common methods for accessing data in PHP, $_GET and $_POST, it may help you remember what attribute you set those values on, and which element it needs to go on. We know WHERE we're submitting, but we need to also say HOW.

As for the mysterious other element and the attribute required for it, watch the video(s) back to see what attribute you need to pull information from an HTML element. Just think, your elements need to have a name for PHP to call in its $_POST array, otherwise how would it know who to call?

Hopefully these hints can get you on the right track, but let me know if you're still unable to pull the correct attributes/values together.

Erik

Christopher Marshall Dyer
Christopher Marshall Dyer
9,760 Points

Got it, thanks! I think the phrasing of the question itself is what through me off, especially the hint. I think it would be helpful if the "process.php" file was accessible in the challenge, because it's a bit too abstract as it is. Anyhow, thanks again!

Erik McClintock
Erik McClintock
45,783 Points

Absolutely, and I totally agree: the phrasing on a lot of the questions for the challenges and quizzes is a bit confusing. Just gotta try a bunch of different things and see what sticks in those cases! And always look out for capitalization...they love to be sticklers there.

Happy to have been of assistance, and happy coding!

Erik