简体   繁体   English

pikaday日期未从php表单发送

[英]pikaday date not being sent from php form

I have searched here and not found a question like mine so I hope someone can help. 我在这里搜索过,没有找到像我这样的问题,所以我希望有人可以提供帮助。

I am using Pikaday responsive in two fields of a form. 我在表单的两个字段中使用Pikaday响应式。 A "from" date and a "to date" Everything looks OK on the form and the dates chosen appear correctly in the form fields, but for some reason the dates are not being sent with the rest of the data from the form. “起始”日期和“截止日期”在表单上一切正常,并且所选日期正确显示在表单字段中,但是由于某些原因,日期未与表单中的其余数据一起发送。

Here is my html: 这是我的html:

  <p>
    <label>BOOK FROM:</label><br />
    <input name="bookfrom" type="date" id="date1" required />&nbsp;<button id="clear" class="SubmitButton">Clear</button>
  </p>


  <p>
    <label>BOOK TO:</label><br />
    <input name="bookto" type="text" id="date2" required />&nbsp;<button id="clear2" class="SubmitButton">Clear</button>
  </p>

and here is my script at the bottom of the page: 这是页面底部的脚本:

<script src="../js/dependencies/jquery.min.js"></script>
<script src="../js/dependencies/moment.min.js"></script>
<script src="../js/dependencies/pikaday.min.js"></script>
<script src="../js/pikaday-responsive.js"></script>
    <script>
       var $date1 = $("#date1");
      var instance1 = pikadayResponsive($date1, {
        format: "Do MMM YYYY",
        outputFormat: "X"
      });
      $date1.on("change", function() {
        $("#output1").html($(this).val());
      });

      $("#clear").click(function() {
        instance1.setDate(null);
      });

        var $date2 = $("#date2");
      var instance2 = pikadayResponsive($date2, {
        format: "Do MMM YYYY",
        outputFormat: "X"
      });
      $date2.on("change", function() {
        $("#output2").html($(this).val());
      });

      $("#clear2").click(function() {
        instance2.setDate(null);
      });
    </script>

after the form has been sent the following test php code: 在表单已发送以下测试php代码后:

$startdate=$_POST['bookfrom'];
echo 'Date from= ' . $startdate . '<br><br>';
$enddate=$_POST['bookto'];
echo 'Date to= ' . $enddate . '<br><br>';
exit();

returns: 收益:

Date from= 起始日期=

Date to= 日期=

there should be a date code after each = sign, but there is nothing. 每个=号后应有一个日期代码,但没有任何内容。

I should say that I am very new to working with JavaScript/query and I think it is probably something to do with that causing the problem. 我应该说我对使用JavaScript /查询非常陌生,我认为这可能与导致问题的原因有关。 I have given the input fields names in the same way as the others in the form and the others all transfer correctly. 我以与表单中其他字段相同的方式给了输入字段名称,其他所有字段均正确传输。 It is just these two date fields that are not getting through. 只是这两个日期字段没有通过。

Because of the JavaScript, should 由于使用JavaScript,因此

$startdate=$_POST['bookfrom'];

and

$enddate=$_POST['bookto'];

be something else? 还有别的吗? I have tried: 我努力了:

$startdate=$_POST['date1'];
echo 'Date from= ' . $startdate . '<br><br>';
$enddate=$_POST['date2'];
echo 'Date to= ' . $enddate . '<br><br>';
exit();

and some other variations using terms in the script instead of the input field names but still get the same result. 以及使用脚本中的术语而不是输入字段名称的其他一些变体,但仍然得到相同的结果。

In the head tag of the page I also have: 在页面的标题标签中,我还有:

 <link rel="stylesheet" href="../css/pikaday-package.css">
 <script src="../js//pikaday-responsive-modernizr.js"></script>

I would appreciate any help. 我将不胜感激任何帮助。

Best wishes 最好的祝愿

Tog 火车

This is a shot in the dark becasue I'm not entirely familiar with Pikaday, but when I used it I generated it like this: 这是在黑暗中拍摄的镜头,因为我对Pikaday并不完全熟悉,但是当我使用它时,它是这样生成的:

var timepicker = new Pikaday({
field: document.getElementById('datepicker'),
firstDay: 1,
minDate: new Date(2016, 0, 1),
maxDate: new Date(2100, 12, 31),
yearRange: [2016,2100],
showTime: true,
autoClose: false,
use24hour: false,
format: 'YYYY-MM-dd'

So my guess is that you generated it incorrectly? 所以我的猜测是您错误地生成了它? Give it a try, but like I said it's a shot in the dark. 试试看,但是就像我说的那样,它是在黑暗中拍摄的。

What an idiot I am. 我真是个白痴。 I spent many hours over two days on this and now the solution hits me like a frieght train. 我花了两个多小时在此上花费了两个小时,现在解决方案像一列火车一样打动了我。 A silly (very silly) typo. 愚蠢的(非常愚蠢的)错字。

I had: 我有:

<script src="../js//pikaday-responsive-modernizr.js"></script>

and it should have been: 它应该是:

<script src="../js/pikaday-responsive-modernizr.js"></script>

Amazing what an extraneous / can do :-) 令人惊讶的是什么无关紧要的:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM