-2

So I want to use a certain type of form and I need to see what the option chosen is. Right now I just want to echo what is chosen, but I have no idea how. For example, if someone wanted to chose 2 it would echo 2. My form:

<label for="format"><strong>Options</strong></label>
<select id="optionsid" name="optionsname">  
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>

EDIT: So after finding out the action part of the tag, I got almost what I wanted, which was having an action on the same file. I want to show the form in the way that it was picked, for example I almost got it here, but I want to show the options number being 2 instead of the one first in the code if 2 was picked after the submit button is hit. Would anyone know how to do that? Sorry for not specifying earlier. My code now is

<form action="" method="post">
<label for="format"><strong>Options</strong></label>
<select id="optionsid" name="optionsname">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>
<button type="submit"> send </button>
</form>

<?php echo $_POST['optionsname'];?>

1 Answers1

1

You need to create a form and retrieve its value(s) inside php with POST or GET methods, something like:

form_select.php

<?php

if(!empty($_POST)){

    echo $_POST['optionsname'];
    exit;
}
?>

<form action="form_select.php" method="post">
<label for="format"><strong>Options</strong></label>
<select id="optionsid" name="optionsname">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>
<button type="submit"> send </button>
</form>
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • 1
    Funny the things that people think are [actual answers](http://stackoverflow.com/questions/41317616/php-checking-select-form-answer/41317638#comment69839350_41317638) - *sigh*. Oh well... bad questions usually attract equally bad/worse answers, not saying the same for yours though ;-) – Funk Forty Niner Dec 25 '16 at 00:17
  • The world if full of "funny things". MC Fred! – Pedro Lobito Dec 25 '16 at 00:21
  • 1
    Haha! yes, we humans can be rather funny and strange animals all rolled up into one. – Funk Forty Niner Dec 25 '16 at 00:21
  • @RicardoOrtegaMagaña I got 27k reputation being sarcastic, the rest were actual answers. – Pedro Lobito Dec 25 '16 at 10:38