Reputation: 987
Here is an input form which passes date type to intermediate.php from a form.
<form action="intermediate.php" method="post">
<input type="date" name="vazhipadudate1" />
</form>
How can i get the picked date i tried this code snippet .It echos as 1970-01-01
Php code snippet.
$date='vazhipadudate1';
$time = strtotime($_POST["$date"]);
$storecart[$i]['date'] = date('Y-m-d', $time);
echo "Selected Date is..........".$storecart[$i]['date'] ;
The output i am getting as
Selected Date is..........1970-01-01
Upvotes: 1
Views: 866
Reputation: 4125
After reproducing the problem,
I think the problem is probably because your submitting the form without passing any value to input
.
As The input
has no def value. So it, POST
s empty string.
And when you pass the empty string to strtotime
that returns false
Amd, again when you pass it to date
that returns 1970-01-01
as (int) FALSE
-> 0
So you should test the POST
before processing it. Something like this to check POST
ed data,
!empty( $_POST["vazhipadudate1"] )
# AND/OR,
$time = strtotime($_POST["$date"]);
if (time === false) /*TakeAppropriateAction*/;
Upvotes: 2