JQuery 日期选择器值未提交

JQuery Datepicker values does not get submitted

我尝试通过 GET 将一些基本数据提交给 PHP 脚本。 我的 5 个值中有两个由 JqueryUI 日期选择器填充。 当我通过警报检查这两个输入字段时,它们正确显示,但是它们没有在提交时传递给 PHP 脚本。

代码: JSFiddle

index.php - 注意:addHourOptions() php 函数只是添加一些 select <option> 字段, 没什么特别的。

<?php
include('inc/functions.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta content="text/html; charset=UTF-8" http-equiv="content-type">
        <title>Filter</title>

        <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
        <script language="javascript" type="text/javascript" src="js/main.js"></script>
        <!--<script language="javascript" type="text/javascript" src="ajax/ajax.js"></script>-->
    </head>
    <body>
            <form id="filter" action="filter.php" method="GET">
                <label for="date-from">
                    from Date: <input id="date-from" type="text" />
                </label>
                &nbsp;
                <label for="date-to">
                    to Date: <input id="date-to" type="text" />
                </label>
                &nbsp;
                <label for="time-from">from Time:
                    <select id="time-from"  name="time-from" size="1">
<?php addHourOptions(); ?>
                    </select>
                </label>
                &nbsp;
                <label for="time-to">to Time:
                    <select id="time-to" name="time-to" size="1">
<?php addHourOptions(); ?>
                    </select>
                </label>
                &nbsp;
                <label for="corps">Corporation:
                    <select id="corps" name="corps" size="1">
                        <option value="98256608">Scroll Lock.</option>
                        <option value="955058602">German Angels</option>
                        <option value="98323502">Rat der 66er</option>
                        <option value="98183461">Girl Friends Please Ignore</option>
                        <option value="98371266">Know your Role</option>
                    </select>
                </label>
                &nbsp;
                <button type="submit" id="filterButton">Filter</button>
                <button type="button" id="debug">Debug</button>
            </form>
    </body>
</html>

main.js

//initialize datepicker: yy-mm-dd / yesterday
$(function(){
    $.datepicker.setDefaults(
            $.extend($.datepicker.regional[''])
            );
    $('#date-from').datepicker({dateFormat: 'yy-mm-dd'}).datepicker("setDate", -1);
    $('#date-to').datepicker({dateFormat: 'yy-mm-dd'}).datepicker("setDate", "TODAY");
});

// set defaults for time timespan-dropdowns
$(function() {
    $('#time-from option[value="19:00"]').attr("selected",true);
    $('#time-to option[value="23:59"]').attr("selected",true);
});

$('#debug').click( function() {
        alert($('#date-from').val() + " " + $('#date-to').val());
}

filter.php - 现在只显示 _GET 变量,没有逻辑

<?php
foreach($_GET as $key => $param){
    echo $key . " => " . $param . "<br />";
}
?>

所以filter.php的输出应该有5行, 每个形式值一个。但是只有3个。

示例输出:

time-from => 19:00
time-to => 23:59
corps => 98256608

谁能告诉我为什么两个输入字段包含 我的日期没有与表格的其余部分一起提交?

提前致谢

编辑:我在这里使用了搜索,并阅读了很多关于它的问题和答案,但似乎对我没有任何帮助。

<label for="date-from">
     from Date: <input id="date-from" type="text" name="date-form" />
</label>
&nbsp;
<label for="date-to">
     to Date: <input id="date-to" type="text" name="date-to" />
</label>

为他们创建名称属性,我想你的问题已经解决了。