Help with PHP code for form with date & time variables
Hello, we have got an online form here, pretty simple one that needs a date and time filled in, it's based on an even simpler contact form that uses Captcha V3 and works fine – https://bit.ly/2NYwom7
when we fill in the form it just produces a page with "Error!" on it, as stated in the PHP code, which is as folows
<?php
//set recaptcha url/secret-key/response
$recapture_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = 'xxxxxxxxxxxxxxxxxxxxx';
$recaptcha_response = $_POST['token'];
//send information to recaptcha url
$recaptcha = file_get_contents($recapture_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha);
//check if recaptcha has been successful
if($recaptcha->success==true) {
if($recaptcha->score >= 0.1) {
// if recaptcha is successful and score is equal or more than 0.1 process the form information
$name = htmlspecialchars($_POST['name']);
$telephone = htmlspecialchars($_POST['telephone']);
$visitdate = htmlspecialchars($_POST['visitdate']);
$arrivaltime = htmlspecialchars($_POST['arrivaltime']);
$departuretime = htmlspecialchars($_POST['departuretime']);
if(empty($name) || empty($telephone) || empty($visitdate) || empty($arrivaltime) || empty($departuretime)) {
$error = true;
$status = "Failed";
}
// if no form errors are set then send the form information to the email address
if(!isset($error)) {
$formcontent=" From: $name \n telephone: $telephone \n visitdate: $visitdate \n arrivaltime: $arrivaltime \n departuretime: $departuretime";
$recipient = "e-mail removed by moderator";
$subject = "Covid 19 Contact Form";
$mailheader = "From: $name \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
$status = "Successful";
}
}
// if recaptcha fails set a status
else {
$status = "Failed";
}
}
// if status is successful then include the contact_sent.html page
if($status === "Successful") {
include('pages/covidform-sent.html');
}
else {
// if status is failed then include the contact_failed.html page
include('pages/covidform-failed.html');
}
?>
best guess is that part of the form that deals with the responses
$name = htmlspecialchars($_POST['name']);
$telephone = htmlspecialchars($_POST['telephone']);
$visitdate = htmlspecialchars($_POST['visitdate']);
$arrivaltime = htmlspecialchars($_POST['arrivaltime']);
$departuretime = htmlspecialchars($_POST['departuretime']);
needs amending to take care of the date and time variables?
Thanks for any assistance!
