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

dmcglone27's avatar

form date field

Hi all, I am building 1 form to do the edit and create of an event but, I can't get the field of type date to show the current db value. all other fields of type text work perfectly.

Does the date form type need anything special? Or is there some special way to do it?

<input id="date" type="date" class="form-control" name="date" value="{{ old('date') }} @isset($event) 
{{ $event->date }} @endisset" required>
0 likes
14 replies
dmcglone27's avatar

@tykus I am using the same form for edit and create, so what's happening here is, I am checking to see if $event is set, and if it is, it will populate the edit form, and if it's not, the form will not be populated. This way one form can be used for editing and creating.

STEREOH's avatar

The old helper has a second parameter for the default value.

<input id="date" type="date" class="form-control" name="date" value="{{ old('date', $event->date ?? '') }}" required>
dmcglone27's avatar

@STEREOH I tried this and this solution seems to only work when I'm using 2 seperate forms for edit and create.

STEREOH's avatar

@dmcglone27 yeah didn't understand that the $event variable wasn't set , what is your php version ?

STEREOH's avatar

@dmcglone27

<input id="date" type="date" class="form-control" name="date" value="{{ old('date', isset($event) ? $event->date : '') }}" required>
dmcglone27's avatar

@STEREOH your suggestion works for both forms, but still doesn't populate the edit form.

I get this on the edit form instead of what's in the db. The create form works as expected. :-(

mm/dd/yyyy
dmcglone27's avatar

@STEREOH all of my type text fields work as expected, it's that date field that doesn't want to work for some odd reason.

STEREOH's avatar
STEREOH
Best Answer
Level 18

@dmcglone27 Format it as yyyy-mm-dd, if you're using carbon :

<input id="date" type="date" class="form-control" name="date" value="{{ old('date', isset($event) ? $event->date->toDateString() : '') }}" required>
dmcglone27's avatar

@STEREOH That's it! Thank you! Can you explain to me what I am not understanding? Was it not working because I wasn't using the correct format?

STEREOH's avatar

@dmcglone27 yes, by default, a carbon instance __toString() ($event->date) returns the datetime (yyyy-mm-dd hh:ii:ss )

and the format expected from a input type date is (yyyy-mm-dd)

1 like

Please or to participate in this conversation.