Solved

Date Variable is Changing to 31 Dec 1969

Posted on 2008-10-07
4
478 Views
Last Modified: 2012-06-21
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
Comment
Question by:dannywareham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:youssefomar
ID: 22664364
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
 
LVL 26

Author Comment

by:dannywareham
ID: 22664685
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
 
LVL 6

Accepted Solution

by:
youssefomar earned 500 total points
ID: 22664825
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
 
LVL 26

Author Closing Comment

by:dannywareham
ID: 31504029
Muchas gracias.
Worked like a  charm :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC 5- How can I post textarea value using @Html.ActionLink? 8 53
Popup write two lines 3 22
Jquery 7 29
Making Table Thru ASP Response.write 5 19
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question