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 trialShane 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