louisav
louisav

Reputation: 382

Laravel form empty date when posted

I have the following view:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
    rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.min.css" />

<form class="form-horizontal" role="form" method="POST" action="{{ route('admin.create_athlete') }}">

{{ csrf_field() }}
<div class="form-group">
    <div class="col-md-6">
        <div class="input-group date" data-provide="datepicker" data-date="2001/01/01">
            <input type="text" readonly="" class="form-control">
            <div class="input-group-addon">
                <span class="glyphicon glyphicon-th"></span>
            </div>
        </div>  
    </div>
</div> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>              
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>    

 <!-- Datepicker -->
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>

      <script type="text/javascript">
        $.fn.datepicker.defaults.format = "yyyy/mm/dd";  
        $('#datepicker').datepicker()
           .on('changeDate', function (ev) {
           $('.datepicker').hide();
        });

        var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
        $.fn.bootstrapDP = datepicker;                 
      </script>

In my controller I'm returning the request to see the data:

public function store(Request $request)
{
    return $request->all();
}

The date field is not even listed: {"_token":"3Klr9x8iNW8GUDtCyX4mZFly3U1WPVIZB63Jwev1","name":"f","surname":"f","gender":"male","cellphone":"5","email":"","idnumber":""}

Why did the date value not submit with the post command?

Upvotes: 1

Views: 1304

Answers (1)

Laerte
Laerte

Reputation: 7083

Try to change this:

<input type="text" readonly="" class="form-control">

to this:

<input name="date" type="text" readonly="" class="form-control">

and check if it works...

The Controller find the fields by the "name" attribute. If you don't put a "name" field in your input, it will not be considered in the post method.

Upvotes: 1

Related Questions