Reputation: 73
I need to get the selected element of the dropdown, in php.
October [1] uses the alias input('value') to get value submitted in the form
, and it works fine for the input
tag, but I'm not sure how do I get the value of the dropdown
?
Many thanks
[1] https://octobercms.com/docs/ajax/introduction
HTML
<form data-request="onTest" >
<input name="value1"> <!-- this works fine -->
<select class="form-control" id="idtitle" name="idtitle">
<option selected disabled hidden>{{default}} </option>
<option>Ms</option>
<option>Mrs</option>
<option>Mr</option>
<option>None</option>
</select>
<!-- Action button -->
<button type="submit">Calculate</button>
</form>
PHP
function onTest()
{
$var= input('value1') ; // OK
$dropdown=input('idtitle'); // NULL
$dropdown= $_GET['idtitle']; // NULL
}
Upvotes: 0
Views: 466
Reputation: 865
Besides \Input::post()
you can get inputs with Input::get('idtitle')
or Input::all()
. Just make sure to have use Input;
declaration if this is in a plugin class file (component.php or class.php).
Also in my testing input('idtitle')
did work for me.
I think why $_GET
doesn't is because this is an ajax post not a typical form post.
Upvotes: 0