Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Shane Roth
5,880 PointsPass 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

Daniel Le Maty
754 Pointsno, 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;
}
?>

Daniel Le Maty
754 PointsHave 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
5,880 Pointsok naming the select seems familiar, I need to pass the variable in post right? so I have input=submit action="process.php?flavor=NAMEOFSELECT>

Shawn Gregory
Courses Plus Student 40,672 PointsShane,
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!

Daniel Le Maty
754 Pointsthen in php just change $_POST to $_GET