I have this array that populates a dropdown menu. The key is my database key and the value is the corresponding database value. The issue I am having is that when I POST the form, I am getting the POSTed numerical value instead of the string value in the dropdown list. I could query the database to get the string but there has to be a better way of doing this as I already have both values in an array. I can’t use array_search because the the array is multidimensional. Can someone please offer a hand?
Thanks
foreach($dd as $k=>$v)
{
echo'<option value="'.$v['ace_id'].'">'.$v['arua'].'</option>';
}
The HTML
inputfields (this also includesselect,textareaandbutton) only sends the name-value pairs to the server side (as been specified in thenameandvalueattribues). They does not send any textual representation along it.You already know the text and the labels in the server side beforehand (how else would you have printed them?), there’s absolutely no point of having them in the request parameters.
You can solve this “problem” in several ways:
valueattribute, not as option label.Update: here’s a basic example (without sanitity checks like
issetandhtmlspecialchars, but that’s up to you):