Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Date Variable is Changing to 31 Dec 1969

Hi all

I have a javascript contact form on a php page.
The javascript is used to verify the field entries (which it does fine). the php file handles the creation of the outgoing emai, and formatting into a table layout.

The issue is with two of the fields - a departure and an arrival date.

Regardless of what is submitted through the form, the output is always Wed 31 Dec 1969.
I'm sure that this is something really simple.
Can anyone help, please?

Thanks

(the file is below)
<?php
 
$ref = $_SERVER['HTTP_REFERER'];
 
$ar="";
 
$dep ="";
 
if(preg_match("(agneswaters.net.au\/agneswater_enquiries\/index.php)",$ref)){
 
extract($_POST);
 
$er[100];
 
 
 
if ($FName!=''){
 
if(!preg_match("/^[a-zA-Z]+$/",$FName)){
 
$er[]="Please use only alpha characters in First Name ";
 
}
 
}else{
 
$er[]="First Name is required";
 
}
 
 
 
if ($LName!=''){
 
if(!preg_match("/^[a-zA-Z]+$/",$LName)){
 
$er[]="Please use only alpha characters in Last Name ";
 
}
 
}
 
	
 
$ar = $ArrMM  . "/" . $ArrDD . "/" . $ArrYY;
 
$dep = $DepMM . "/" . $DepDD  . "/" . $DepYY;
 
$ar =date('m/d/Y',strtotime($ar));
 
$dep =date('m/d/Y',strtotime($dep));
 
if ($dep<=$ar){
 
$er[]="Departure date must be after arrival date";
 
}
 
 
 
if ($Country!=''){
 
if(!preg_match("/^[a-zA-Z]+$/",$Country)){
 
$er[]="Country is required must only have Alphabets";
 
}}else{
 
$er[]="Country is required";
 
}
 
 
 
 
 
if ($email!=''){
 
if(!preg_match("/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/",$email)){
 
$er[]="Please enter valid email";
 
}
 
}else{
 
$er[]="Email is required";
 
}
 
 
 
if ($Phone!=''){
 
if(!preg_match("/^\d+$/",$Phone)){
 
$er[]="Phone Number must not contain alpha characters";
 
}
 
}
 
else{
 
$er[]="Phone Number is required";
 
}
 
 
 
 
 
if ($MPhone!=''){
 
if(!preg_match("/^\d+$/",$MPhone)){
 
$er[]="Mobile Number must not contain alpha characters";
 
}
 
}
 
$add = trim(strip_tags($AddInf));
 
if ($add!=''){
 
if(preg_match("(http:|ftp|http:\/\/|https:\/\/|www.|.com|.net)",$add)){
 
$er[]="Comment / Feedback must not contain URL or any other HTML Tag";
 
}
 
}
 
if ($captcha==''){
 
$er[]="Security Code is required";
 
}elseif ($captcha!=''){
 
if ($captcha!=$cap2){
 
$er[]="Please enter correct Security code";
 
}
 
}
 
 
 
if (count($er)>0){
 
echo "Please Correct the following Errors<br><ul>";
 
foreach ($er as $e){
 
echo "<li>$e</li>";
 
}
 
echo "</ul>";
 
exit;
 
}else{
 
$msg='<style>
 
.stl td{
 
font-family:Arial, Helvetica, sans-serif;
 
font-size:12px;
 
background-color:#F4F4F4;
 
}
 
</style>
 
           <table width="703" border="0" align="center" cellpadding="3" cellspacing="2" class="stl">
 
  <tr>
 
    <td colspan="4" style="background-color:#999999;"><strong>Enquiry From Website </strong></td>
 
  </tr>
 
  <tr>
 
    <td width="132" >First Name </td>
 
    <td width="222" >' . $_POST['FName'] . '</td>
 
    <td width="118" >Last Name </td>
 
    <td width="197" >' . $_POST['LName'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Town</td>
 
    <td >' . $_POST['Town'] . '</td>
 
    <td >Country</td>
 
    <td >' . $_POST['Country'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Arriving Date </td>
 
    <td >' . date("D d, M Y",strtotime($ar)) . ' </td>
 
    <td >Departing</td>
 
    <td >' . date("D d, M Y",strtotime($dep))  . ' </td>
 
  </tr>
 
  <tr>
 
    <td >Number of Persons </td>
 
    <td >' . $_POST['NumPers'] . '</td>
 
    <td >Email</td>
 
    <td >' . $_POST['email'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Phone Number </td>
 
    <td >' . $_POST['Phone'] . '</td>
 
    <td >Mobile Number </td>
 
    <td >' . $_POST['MPhone'] . '</td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >Additional Information or Question </td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >' . $_POST['AddInf'] . '</td>
 
  </tr>
 
</table>
 
';
 
$to = 'steve@agneswaters.com.au';
 
$subject = 'Enquiry from Agnes Water Website';
 
$headers .= 'From: Agnes Water Website <steve@agneswaters.com.au>' . "\r\n";
 
$headers .= 'MIME-Version: 1.0' . "\r\n";
 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
mail($to, $subject, $msg, $headers);
 
header("Location:http://www.agneswater.net.au/agneswater_enquiries/success.php");
 
}
 
}else{
 
//echo 'dont be too smart <br> dont call it directly';
$msg='<style>
 
.stl td{
 
font-family:Arial, Helvetica, sans-serif;
 
font-size:12px;
 
background-color:#F4F4F4;
 
}
 
</style>
 
           <table width="703" border="0" align="center" cellpadding="3" cellspacing="2" class="stl">
 
  <tr>
 
    <td colspan="4" style="background-color:#999999;"><strong>Enquiry From Website </strong></td>
 
  </tr>
 
  <tr>
 
    <td width="132" >First Name </td>
 
    <td width="222" >' . $_POST['FName'] . '</td>
 
    <td width="118" >Last Name </td>
 
    <td width="197" >' . $_POST['LName'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Town</td>
 
    <td >' . $_POST['Town'] . '</td>
 
    <td >Country</td>
 
    <td >' . $_POST['Country'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Arriving Date </td>
 
    <td >' . date("D d, M Y",strtotime($ar)) . ' </td>
 
    <td >Departing</td>
 
    <td >' . date("D d, M Y",strtotime($dep))  . ' </td>
 
  </tr>
 
  <tr>
 
    <td >Number of Persons </td>
 
    <td >' . $_POST['NumPers'] . '</td>
 
    <td >Email</td>
 
    <td >' . $_POST['email'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Phone Number </td>
 
    <td >' . $_POST['Phone'] . '</td>
 
    <td >Mobile Number </td>
 
    <td >' . $_POST['MPhone'] . '</td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >Additional Information or Question </td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >' . $_POST['AddInf'] . '</td>
 
  </tr>
 
</table>
 
';
 
//$to = 'steve@agneswaters.com.au';
 
$to = 'danny@datamouse.biz';
 
$subject = 'Enquiry from Agnes Water Website';
 
$headers .= 'From: Agnes Water Website <steve@agneswaters.com.au>' . "\r\n";
 
$headers .= 'MIME-Version: 1.0' . "\r\n";
 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
mail($to, $subject, $msg, $headers);
 
header("Location:http://www.agneswater.net.au/agneswater_enquiries/success.php");
 
}
 
?>

Open in new window

0
dannywareham
Asked:
dannywareham
  • 2
  • 2
1 Solution
 
youssefomarCommented:
I think the problem is you are creating the arrival and departure date like this:
$ar = $ArrMM  . "/" . $ArrDD . "/" . $ArrYY;
 
$dep = $DepMM . "/" . $DepDD  . "/" . $DepYY;
 
$ar =date('m/d/Y',strtotime($ar));
 
$dep =date('m/d/Y',strtotime($dep));

and all these values   $ArrMM , $ArrDD, $ArrYY; $DepMM,  $DepDD ,  $DepYY;
Don't have values

so $ar and $dep will be equal to "//" this is what causing the strtotime() function to give you 1969 date
0
 
dannywarehamAuthor Commented:
Aren't these values passed from the javascript form?
They are the form values:


function testDate(theForm) {
  var now = new Date();
  var thisYear = now.getFullYear();
  var jan1 = Date.UTC(thisYear, 0, 1);
  now = Date.UTC(now.getFullYear(),now.getMonth(), now.getDate());
  var arrival = Date.UTC(theForm["ArrYY"].value, (parseInt(theForm["ArrMM"].value) - 1), theForm["ArrDD"].value);
  var departure = Date.UTC(theForm["DepYY"].value, (parseInt(theForm["DepMM"].value) - 1), theForm["DepDD"].value);
  if (arrival == jan1) {
    alert("Arrival date cannot be January 1st "+thisYear);
    theForm["ArrDD"].focus();
    return false;
  }
  if (arrival >= departure) {
    alert("Departure date must be after arrival date");
    theForm["DepDD"].focus();
    return false;
  }
  if (departure < now) {
    alert("Departure date must be in the future");
    theForm["DepDD"].focus();
    return false;
  }
  if (arrival < now) {
    alert("Arrival date must be in the future");
    theForm["ArrDD"].focus();
    return false;
  }
  return true;
}

Open in new window

0
 
youssefomarCommented:
if these variable being passed from HTML then you need to use $_POST to read them :

try this

$ar = $_POST['ArrMM']  . "/" . $_POST['ArrDD'] . "/" . $_POST['ArrYY'];
 
$dep = $_POST['DepMM'] . "/" . $_POST['DepDD']  . "/" . $_POST['DepYY'];

Open in new window

0
 
dannywarehamAuthor Commented:
Muchas gracias.
Worked like a  charm :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now