Stanislas Piotrowski Stanislas Piotrowski - 1 year ago 155
PHP Question

input type date html5 and receiving data from databse

I'm working on

locally with
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
) 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.

Answer Source

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'>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download