I have a form that has a field pulled from the database as a dropdown. I need to get the text selected in the dropdown but I don’t know in advance what the field ID will be.
This is basically just a form that has already been generated. I don’t need to pull anything from the database, it’s already on this page. All I need to do is get the form information and email it, no writing to the database.
I know how to do the _Request for the other fields based on the ID but I’m not sure how to do this one. The ID changes. It can be ID=1, ID-2, etc.
I need to do something like: _REQUEST form element where ID is LIKE “ID[*]” or something similar.
Any suggestions or links to tutorials?
Here are a couple samples of what the dropdown renders on the page:
<div class="wrapperAttribsOptions">
<h4 class="optionName back"><label class="attribsSelect" for="attrib- 1">Model</label></h4>
<div class="back">
<select name="id[1]" id="attrib-1">
<option value="45">VC3-4C</option>
<option value="1">VC3-4PG</option>
<option value="3">VC3-4SG</option>
<div class="wrapperAttribsOptions">
<h4 class="optionName back"><label class="attribsSelect" for="attrib-14">SPK Model</label></h4>
<div class="back">
<select name="id[14]" id="attrib-14">
<option value="43">SPK-4</option>
<option value="44">SPK-8</option>
</select>
TIA
The brackets [] mean that PHP will create an array variable with the posted values. So you should have
$_REQUEST['id']as an array. There should be a value keyed by the number in the form ($_REQUEST['id'][1]in your first example,$_REQUEST['id'][14]in your second).If there will just be one value (you don’t say what you’re trying to do with these values) then you can just shift it off the array.
If there will be multiple values, you can loop through them: