Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rakeshsonea@gmail.com's avatar

A Date picker

Can anyone please suggest me a very easy way to place a datepicker in a form in laravel. I have tried to use the form::month and form::year..but when it comes to the date...i will need to put a validation so that the user cannot choose a date like 31 Feb...and this is out of my capability right now. I have also looked for bootstrap 3 datepicker..but its inclusion seems to be difficult ....any help is most welcome...

0 likes
15 replies
RachidLaasri's avatar

You can use jQuery UI Datepicker http://jqueryui.com/datepicker/

Include this in your head

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

in your footer

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>

and your input

{{ Form::text('date', '', array('id' => 'datepicker') }}
5 likes
rakeshsonea@gmail.com's avatar

@Rachid Oh...thank you very much ...it works...however i have one inconvenient....since i will be using the datepicker for entering the date of birth...the user will have to click many so that to get the right date of birth....do you have any suggestion which can remove this inconvenience....again thanks for your precious help....

zhiyong's avatar

When I tried RachidLaasri's solution, I got an error saying "unexpected ';' " a few line lines after where I insert

{{ Form::text('date', '', array('id' => 'datepicker') }}

But in fact I don't have any ';' in that view file.

I am using Laravel 5. What I am missing here? Could this be a dependency issue or something else?

Thanks in advance.

uxweb's avatar

@zhiyong if you are using L5 use should use the new output tags in blade:

    {!! Form::text('date', '', array('id' => 'datepicker') !!}
zhiyong's avatar

@uxweb Thanks for the reply.

This is actually what I did. I basically put the stuff RachidLaasri provided into header and footer of app.blade.php. Then in a test page (View), I used following code:

@extends('app')
@section('content')
{!! Form::open(array('url' => $type, 'class' => 'form')) !!}
{!! Form::text('date', '', array('id' => 'datepicker') !!}
{!! Form::close() !!}
This is an test page
@endsection

I got an error: syntax error, unexpected ';'

uxweb's avatar

This view looks good, does the error stack provides the file and error line?

RachidLaasri's avatar

@zhiyong You are missing a ) in your code

{!! Form::text('date', '', array('id' => 'datepicker')) !!}
zhiyong's avatar

@RachidLaasri
Yes, that is the problem. Thanks very much. I should have caught it.

I think a 'a' is also missing from your code. Adding it may help newbies like me in the future. :)

@codeatbusiness Thanks for the link. I will look into them.

athulpraj's avatar

if we are using text form for entering dates ... the input form can be initially filled with text input right? .. how to avoid this?

Please or to participate in this conversation.