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

Shane Roth
Shane Roth
5,880 Points

Pass value of flavor from the select box

I have tried to look through the videos to find this. I know I can set a value by $flavor="" but to get the value from the select and pass it to post. I though this was done using php in the form submit redirection. I am obviously confused and can't find the answer in the videos

4 Answers

no, if you are posting your form you would do something like this

<form method="POST" action="process.php">
<select name="select">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<input type="submit" name="go" value="GO" />
</form>

in the php do something like this

<?php

if(isset($_POST['go'])){

$select = $_POST['select'];

echo $select;

}

?>

Have you give your select box a name?

so for example if you had a select box like

<select name="coolbox"> <option value="val1">Option 1</option> <option value="val2">Option 2</option> <option value="val3">Option 3</option> </select>

Then you could get the result in php after you submit the form like so

$select = $_POST['coolbox'];

Shane Roth
Shane Roth
5,880 Points

ok naming the select seems familiar, I need to pass the variable in post right? so I have input=submit action="process.php?flavor=NAMEOFSELECT>

Shane,

If you want the selection to be appended to the end of the URL, you will need to switch the form method from post to get. Get will send all the form information via the URL. Post will send all form information in the background and not in the URL. If you need the form information in the URL, switch the form method to GET.

Cheers!

then in php just change $_POST to $_GET