Pass value through POST with select option PHP

0

I want to pass the name of the options by POST to another page. I used this but did not recognize the variable.

echo "<form method=POST action=_search.php>";
echo "<select name=selectoption>";
    echo "<option value=nom>nome</option>";
    echo "<option value=prenom>ultimo</option>";
echo "</select>";
echo "<input type=submit name=btnsearch value=search >";
echo "</form>";

And on the other page to receive the value,

$var = $_POST['selectoption'];
echo $var;  
    
asked by anonymous 11.11.2014 / 12:39

1 answer

2

It seems that your problem is that you are confusing value with the description of your <option> because I have tested these two codes here and it is working:

  

prenom

and

  

nom

In the case, you have the 'name' and 'last' option only with values of 'nom' and 'prenom' which are the values returned by $_POST['selectoption'];

So if you want to get 'name' and 'last' instead of 'nom' and 'prenom' you should use following html in your <option> :

echo "<select name=selectoption>";
echo "<option value=nome>nome</option>";
echo "<option value=ultimo>ultimo</option>";
echo "</select>";

When submitting the form you will have:

  

name

or

  

last

Note:

I used your codes to perform the tests, so all of the above statements are correct.

    
11.11.2014 / 12:55