input type date html5 and receiving data from databse
Solution 1
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'>
Solution 2
Use
placeholder="<?php echo date('d/m/Y',strtotime($data["congestart"])) ?>"
instead of putting it in value.
If this doesn't solve the answer, Then explain a little more about what you want to do?
Stanislas Piotrowski
Updated on September 07, 2021Comments
-
Stanislas Piotrowski over 2 years
I'm working on
Chrome
locally withWAMP
,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 byvar_dump
) he displays a placeholderDay / 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.