I'm trying to create a custom function to validate the date & I'm following a tutorial, the first code is before the changes, the second is after. After I try and run the changed code I get an undefined variable: date error related to line if ($time = strtotime($date))
if($_SERVER['REQUEST_METHOD'] === 'POST'){
$date = trim($_POST['date']);
$email = trim($_POST['email']);
$description = trim($_POST['desc']);
if (!empty($date) && !empty($email) && !empty($description)) {
***if ($time = strtotime($date)) {
echo '<p>Date:'. date('F jS Y' ,$time).'</p>';***
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<p>Email: $email</p>";
}
echo '<p>' . strip_tags($description) . '</p>';
}
}
if($_SERVER['REQUEST_METHOD'] === 'POST'){
$date = trim($_POST['date']);
$email = trim($_POST['email']);
$description = trim($_POST['desc']);
***function validate_date($date_string)
{
if ($time = strtotime($date)) {
return date('F jS Y', $time);
} else {
return $date_string . ' does not look valid.';***
}
}
if (!empty($date) && !empty($email) && !empty($description)) {
***echo validate_date($date);***
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<p>Email: $email</p>";
}
echo '<p>' . strip_tags($description) . '</p>';
}
}