Adam Silva Adam Silva - 1 year ago 121
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>

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


But it's returning
. Any idea why?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download