I created a form in html and the inputs are posted to a text file with PHP. I want to add a date stamp when the inputs are submitted to the text file. With my code, it doesn't print out the date.
php file:
<?php
if(isset($_POST['email'])) {
$file = "loginRequest.txt";
$company_name = $_POST['Company_name'];
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$account_num = $_POST['Account_num'];
$address = $_POST['Address'];
$city = $_POST['City'];
$state = $_POST['State'];
$zip = $_POST['Zip'];
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$date = $_POST['todayDate'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$email_message = "Form details below.\r\n";
$email_message .= "First Name: $first_name\r\n";
$email_message .= "Last Name: $last_name\r\n";
$email_message .= "Account#: $account_num\r\n";
$email_message .= "Address: $address\r\n";
$email_message .= "City: $city\r\n";
$email_message .= "State: $state\r\n";
$email_message .= "Zip: $zip\r\n";
$email_message .= "Email: $email_from\r\n";
$email_message .= "Telephone: $telephone\r\n";
$email_message .= "Company Name: $company_name\r\n\r\n";
$fp = fopen($file, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $email_message) or die("Couldn't write values to file!");
fclose($fp);
?>
my form in html:
<!-- WORK IN PROGRESSS: this is the hidden input for the date stamp-->
<tr>
<td>
<input type="hidden" name="startdate" id="todayDate"/>
</td>
</tr>
Javascript logic to get the date:
<!-- hidden date stamp logic -->
<script type="text/javascript">
function getDate(){
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
today = yyyy+""+mm+""+dd;
document.getElementById("todayDate").value = today;
};
//call getDate() when loading the page
getDate();