【问题标题】:JQuery Datepicker values does not get submitted未提交 JQuery Datepicker 值
【发布时间】:2016-09-30 10:17:03
【问题描述】:

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

代码: JSFiddle

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

<?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

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

提前致谢

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

【问题讨论】:

  • 如果这些输入字段在 css 中的某处设置为“display: none”,它们将不会被提交。
  • @AlekosDordas 他们不是,但很高兴知道,我当然不知道。

标签: javascript jquery html jquery-ui jquery-ui-datepicker


【解决方案1】:
<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>

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

【讨论】:

  • 杰普,现在我觉得自己很愚蠢......非常感谢,我不知道我怎么会错过。现在工作正常。
  • 没关系,没必要觉得自己笨。这可能发生在任何人身上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-22
  • 1970-01-01
  • 2019-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多