Adam Silva Adam Silva - 29 days ago 16
PHP Question

Laravel 5.3 Send Selected Dropdown to Controller

I'm using Laravel 5.3 and I have a client registration form, then when a button is clicked, it goes to the corresponding route and then from there to the create method.

I'm having trouble sending my selected dropdown list item to the controller.
Here is my dropdown list:

<div class="form-group">
<label for="card_type" class="col-md-4 control-label">Card</label>
<div class="col-md-6">
<select class="form-control" name="card_type" id="card_type">
<option id="card_id" name="card_id" value="1">One</option>
<option id="card_id" name="card_id" value="2">Two</option>
<option id="card_id" name="card_id" value="3">Three</option>
<option id="card_id" name="card_id" value="4">Four</option>
<option id="card_id" name="card_id" value="5">Five</option>
<option id="card_id" name="card_id" value="6">Six</option>
<option id="card_id" name="card_id" value="7">Seven</option>
</select>
</div>
</div>


Here is what I've tried in the controller to retrieve the selected item:

$request->input('card_id'),
and
$request->input('card_type'),


But it's returning
Null
. Any idea why?

Answer

Use input('card_type'), AND DELETE name="card_id" from your options, you need insert only one name in your input, it must be inserted in select section html

Comments