I'm new to PHP, and I can't figure this out.
I'm trying to figure out how to access the data of a group of select boxes I have defined in my HTML code. I tried grouping them as a class, but that doesn't seem to work... maybe I was doing it wrong.
This is the following HTML code.
<form action="" method="post">
<select class="foo">
<option> 1.....100</option>
</select>
<select class="foo">
<opti开发者_运维问答on> 1.... 500></option>
</select>
<input type="submit" value="Submit" name="submit"/>
</form>
I essentially want to group all my select boxes and access all the values in my PHP code.
Thanks
Use the name attribute in your select tags. Then you can access those fields by name in the $_POST variable.
<form action="" method="post">
<select name="number_one">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>
<select name="number_two">
<option value='a'>1</option>
<option value='b'>2</option>
<option value='c'>3</option>
</select>
<input type="text" name="something"/>
<input type="hidden" name="hidden_value" value="hidden"/>
<input type="submit" value="Submit" name="submit"/>
</form>
In your PHP you can access these like so:
$number_one = $_POST['number_one'];
$number_two = $_POST['number_two'];
$something = $_POST['something'];
$hidden_value = $_POST['hidden_value'];
精彩评论