Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input type date html5 and receiving data from databse

Tags:

html

date

php

input

I'm working on Chrome locally with WAMP, PHP version 5. I use an input type date, which displays a calendar. In fact I get some variables within the data editing page of my users. The concern I have is that all the data are collected. However for date, instead of displaying the record in the database (confirmed by var_dump) he displays a placeholder Day / Month / Year

which does not interest me, I want this placeholder if and only if my field is empty.

Here is the syntax of the field:

<input name="datedepart" type="date"  value="<?php echo date('d/m/Y',strtotime($data["congestart"])) ?>"/>

Is there a way for that?

Receive dear All my utmost respect.

like image 635
Stanislas Piotrowski Avatar asked Aug 22 '12 07:08

Stanislas Piotrowski


1 Answers

Yes, it will probably be enough to change the date format to ISO, like 2012-08-22:

<input name="datedepart" type="date"
value="<?php echo date('Y-m-d',strtotime($data["congestart"])) ?>"/>

If your server expects some other format, you will have to convert it using Javascript (ISO is the standard used in HTML5 specification, so the value of the input field will always be ISO, no matter how Chrome displays it).

update, clarification:

Date field can only contain a valid date. When you try to set it it to some random garbage, then the value becomes empty. When the value is empty - Chrome displays the placeholder. The only valid format for dates in HTML5 is ISO: 2012-03-04. Just try and see:

<input value='2004-02-12' type='date'>
like image 60
fdreger Avatar answered Oct 13 '22 11:10

fdreger