Reputation: 935
Hi guys so i have this update page where i need to display data of a user that are currently inside my database. Among this data is the birthday of the user so im trying display the birthday on Form::input that is a datepicker but the birthday can't be seen any idea on how will i make the datepicker display the birthday of the user from the database? for now i have this code
<div class="form-group">
{{ Form::label('date', 'Birthday') }} Current: {{ $sinf->Birthdate }} </br>
{{ Form::input('date', '$sinf->Birthdate', Input::old('date'), ['class'=>'datepicker', 'placeholder' => '$sinf->Birthdate']) }}<span class="errmsg" style="color:red"><i>{{ $errors->first('date', ':message') }}</i></span>
</div>
Upvotes: 1
Views: 3843
Reputation: 44526
There are a few things wrong with your code as listed below:
1. Date input elements don't have placeholder attributes as per the W3C HTML5 Recommendation.
2. The order and values you pass to the Form::input
method don't match the ones defined by the API. The Illuminate\Html\FormBuilder::input
method accepts the following parameters in the following order: type, name, value, options.
3. The value you pass to the date input must be in ISO 8601 format (meaning YYYY-MM-DD
), although the browsers will use their own presentation format which may differ from browser to browser (for example Chrome will display the date according to the client locale, so you while you pass the date in the required format of YYYY-MM-DD
, it might be displayed as DD/MM/YYYY
, that however is not an issue because the value that will be passed back to the server will still be in ISO 8601 format). This last point may not be an actual issue, as you haven't specified the value of $sinf->Birthdate
, but it was worth mentioning.
So based on the points made above your date input code should look something like this:
{{ Form::input('date', 'birthdate', $sinf->Birthdate, ['class'=>'datepicker']) }}
So assuming the value of $sinf->Birthdate
is equal to 2015-02-22
then the HTML generated by that will be:
<input class="datepicker" name="birthdate" type="date" value="2015-02-22">
And it will show the birthdate value correctly in the browser.
Upvotes: 3