2017-03-08 32 views
0

システムにイベントをプレビューして送信して実際にデータベースに保存するシステムを作成しています。AJAX日付が正しく表示されない日付

私はAJAX呼び出しを使用して変数を収集し、それらを処理し、戻り値をJavascriptに入力してdivに表示する変数に連結します。私は、Bootstrap DatepickerとBootstrap Timepickerを使用して、ユーザーが日付と時刻を選択し、これらを一緒に1つの変数に追加できるようにしています。これは、表示されるために返されるHTMLコード文字列に連結されます。問題は、表示された日付が入力した日付とは全く関係がないことです。提案された修正が評価されます。

Input

出力 午前1時33分37秒 - 01/01/70

日付ピッカー/ Timepickerコンフィグ

$('#dteEStart').datepicker({ 
    autoclose: true, 
    format: 'dd/mm/yyyy', 
    startView: 'year' 
}); 
$('#dteEEnd').datepicker({ 
    autoclose: true, 
    format: 'dd/mm/yyyy', 
    startView: 'year' 
}); 
$('#dteESUDeadline').datepicker({ 
    autoclose: true, 
    format: 'dd/mm/yyyy', 
    startView: 'year' 
}); 
$(".timepicker").timepicker({ 
    showInputs: false, 
    minuteStep: 1 
}); 

のJavascript/AJAX呼び出し

function UpdateEventPreview(){ 
    $('#divError').css('display', 'none'); 

    var StrETitle = $("txtETitle").val(); 
    var DteEStart = $("#dteEStart").val(); 
    var TimeEStart = $("#timeEStart").val(); 
    var DteEEnd = $("#dteEEnd").val(); 
    var TimeEEnd = $("#timeEEnd").val(); 
    var DteESUDeadline = $("#dteESUDeadline").val(); 
    var IntEMaleS = $("#numEMaleS").val(); 
    var IntEFemaleS = $("#numEFemaleS").val(); 
    var IntEPTag = $("#sltEPTag").val(); 

    var LstTags = []; 
    for (var i = 0; i < $('#sltETags').select2('data').length; i++) { 
     LstTags.push(Number($('#sltETags').select2('data')[i].id)); 
    } 
    LstTags = JSON.stringify(LstTags); 

    var StrEDesc = $('#txtEDesc').val(); 
    var StrEReq = $('#txtEReq').val(); 

    $.post('https://thomas-smyth.co.uk/functions/php/fncupdateeventpreview.php', {StrETitle: StrETitle, DteEStart: DteEStart, TimeEStart: TimeEStart, DteEEnd: DteEEnd, TimeEEnd, DteESUDeadline: DteESUDeadline, IntEMaleS: IntEMaleS, IntEFemaleS: IntEFemaleS, IntEPTag: IntEPTag, LstTags: LstTags, StrEDesc: StrEDesc, StrEReq: StrEReq}, function(data){ 
     if(data == 10){ 
      window.location.href = "https://thomas-smyth.co.uk/login"; 
     } 
     else if (data == 11){ 
      $('#divError').css('display', ''); 
      $("#pError").text('HTML Injection Detected!'); 
     } 
     else{ 
      $("#divEventPreview").html(data); 
     } 
    }); 
} 

私はバグの原因が何であるかを発見したと考えているいくつかのより多くのテストではPHP

<?php 
session_start(); 

require "tagHandler.php"; 
$TagManager = new tagHandler(); 

//Retrieves variables from Javascript. 
$StrETitle = $_POST["StrETitle"]; 
$DteEStart = $_POST["DteEStart"]; 
$TimeEStart = $_POST["TimeEStart"]; 
$DteEEnd = $_POST["DteEEnd"]; 
$TimeEEnd = $_POST["TimeEEnd"]; 
$IntEMaleS = $_POST["IntEMaleS"]; 
$IntEFemaleS = $_POST["IntEFemaleS"]; 
$IntEPTag = $_POST["IntEPTag"]; 
$StrEDesc = $_POST["StrEDesc"]; 
$StrEReq = $_POST["StrEReq"]; 

$LstTags = array(); 
$LstTags = json_decode($_POST["LstTags"]); 

if(!isset($_SESSION["LoginDetails"]) || $_SESSION["LoginDetails"][1] != "Staff" && $_SESSION["LoginDetails"][1] != "Developer"){ 
    $data = 10; 
} 
else if($StrETitle != strip_tags($StrETitle)){ 
    $data = 11; 
} 
else { 
    $data = '<div class="box box-widget widget-user"> 
         <div class="widget-user-header" style="background-color: #'.$TagManager->getTag($IntEPTag)[2].';"> 
          <h3 class="widget-user-username">'.$StrETitle.'</h3> 
          <h5 class="widget-user-desc">'.$TagManager->getTag($IntEPTag)[1].'</h5> 
         </div> 
         <div class="widget-user-image"> 
          <img class="img-circle" src="../dist/img/user2-160x160.jpg" alt="User Avatar"> 
         </div> 
         <div class="box-footer"> 
          <div class="row"> 
           <div class="col-sm-4 border-right"> 
            <div class="description-block"> 
             <h5 class="description-header">Start Date</h5> 
             <span class="description-text">'.date('H:i:s d/m/y', strtotime($DteEStart.' '.$TimeEStart)).'</span> 
            </div> 
           </div> 
           <div class="col-sm-4 border-right"> 
            <div class="description-block"> 
             <h5 class="description-header">Sign Up Deadline</h5> 
             <span class="description-text">'.date('Y-m-d', strtotime($_POST["DteESUDeadline"])).'</span> 
            </div> 
           </div> 
           <div class="col-sm-4"> 
            <div class="description-block"> 
             <h5 class="description-header">End Date</h5> 
             <span class="description-text">'.date('H:i:s d/m/y', strtotime($DteEEnd.' '.$TimeEEnd)).'</span> 
            </div> 
           </div> 
          </div> 
         </div> 
         <div class="row"> 
          <div class="col-md-6"> 
           <div class="box-header with-border" style="text-align: center;"> 
            <h3 class="box-title"><i class="fa fa-info-circle"></i> Description</h3> 
           </div> 
           <div class="box-body" style="text-align: center;">'.$StrEDesc.'</div> 
          </div> 
          <div class="col-md-6"> 
           <div class="box-header with-border" style="text-align: center;"> 
            <h3 class="box-title"><i class="fa fa-exclamation-triangle"></i> Requirements</h3> 
           </div> 
           <div class="box-body" style="text-align: center;">'.$StrEReq.'</div> 
          </div> 
         </div> 
        </div>'; 
} 
echo $data; 
?> 

更新 。日付が互いに月と日を混同しているようです。したがって、日が12より大きい場合、日付が無効であると考えられるのでランダムな日付が生成されますが、1から12の間では動作します。

+0

あなたが入力しているものは何ですか? –

+0

私が入力したものが何であっても、入力しても機能しません。私は自分の質問にスクリーンショットを追加しました(正しくロードされているかどうかわからず、私の学校ネットワークが画像をブロックしています)。 –

答えて

1

あなたは、実際の問題は、PHPコードにここにある古い質問Strtotime() doesn't work with dd/mm/YYYY format から参照を取得することができます

<span class="description-text">'.date('H:i:s d/m/y', strtotime($DteEStart.' '.$TimeEStart)).'</span> 

FIX PHPで

$DteEStart = $_POST["DteEStart"]; 
$DteEStart = str_replace('/', '-', $DteEStart); 
echo date('H:i:s d/m/y', strtotime($DteEStart.' '.$TimeEStart)); 

またはJS

$('#dteEStart').datepicker({ 
    autoclose: true, 
    format: 'dd-mm-yyyy',/*change date formate*/ 
    startView: 'year' 
}); 

あなたはコードを実行して見ることができます

<?php 
$DteEStart="22/02/2017"; 
$DteEStart = str_replace('/', '-', $DteEStart); /*see result with commenting and without commenting this line*/ 
$TimeEStart="10:45 AM"; 
$r=date('H:i:s d/m/y', strtotime($DteEStart.' '.$TimeEStart)); 
echo $r; 
?> 
関連する問題