【问题标题】:Obtaining Date as string from bootstrap-datetimepicker从 bootstrap-datetimepicker 获取日期作为字符串
【发布时间】:2015-11-26 20:25:42
【问题描述】:

我正在使用 bootstrap 和 jquery 创建一个使用 php 文件搜索数据库的表单,我设法毫无问题地添加了过滤器,我的问题是现在我已经使用 Bootstrap-DateTimePicker 添加了一个日期选择器,而那里在表单中显示日期没有问题,我似乎无法将日期的实际字符串作为变量获取到我的 php 文件中。

这是现在的表单 HTML:

<form id="buscarInv" action="index.php" method="post" class="navbar-form pull-left" role="search">
          <div class="form-group">
            <div class="input-group-btn search-panel">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                  <span id="search_concept">Filtrar</span> <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" id="search-filter" role="menu">
                  <?php print("$salida");?>
                </ul>
                <input type="hidden" name="search_param" value="" id="search_param">         
                <input type="text" class="form-control" name="searchinv" placeholder="Buscar" onkeydown="searchq();">
            </div>
        </div>
        <div class='input-group date' name='datetimepicker1' id='datetimepicker1'>
              <span class="input-group-addon">
                <span class="glyphicon glyphicon-calendar"></span> Date
              </span>
            <input type='text' data-date-format="YYYY-MM-DD" class="form-control" placeholder="Fecha" name="fechaC" id="fechaC">
        </div>
     </form>

这里是 DateTimePicker 脚本和将输入发送到 php 文件的脚本。 日期时间选择器:

$(function () {
            $('#datetimepicker1').datetimepicker({format: 'YYYY-MM-DD'});

        });

搜索:

function searchq(){
  var searchTxt = $("input[name='searchinv']").val();
  var filter = $("input[name='search_param']").val();
  var fechaEnv = $("input[name='fechaC']").val();
   $.post("search.php",{searchVal: searchTxt, filter:filter, fechaEnv:fechaEnv}, function(output){
    $("#output").html(output);
  });
}

我尝试使用 name='datetimepicker1',尝试在 datetimepicker 函数中设置 fechaC 的值,但似乎没有任何效果,我是否遗漏了什么?

更新:添加了 PHP

 $output='<thead>
            <tr>
              <th>Producto</th>
              <th>Cantidad</th>
              <th>Precio</th>
              <th>Locacion</th>
              <th>Fecha</th>
            </tr>
          </thead>
          <tbody>';
$idcat='';
$fechaT = date('Y-m-d');
if(isset($_POST['searchVal'])){
  $searchq = $_POST['searchVal'];
  if(isset($_POST['fechaEnv'])){
      $fechaT = $fechaEnv;
      $output .= '<tr><td>Date should be displayed here: '.$fechaEnv.'</td></tr>';
    }

然而,当我回显输出时,它显示为:“日期应在此处显示:”而不添加日期

【问题讨论】:

  • 尝试做一个 var_dump($_REQUEST);在 search.php 和 die() 中,查看是否发送了 var fechaC
  • 结果是:'searchVal' => string 'lib' (length=3) 'filter' => string '' (length=0) 'fechaEnv' => string '2015-09- 30'(长度=10)。但是当我尝试将其分配给输出时,它显示为空白,这让我相信问题可能出在 php 方面

标签: javascript php jquery twitter-bootstrap-3 bootstrap-datetimepicker


【解决方案1】:

忘记收集 fechaEnv like $_POST, $fechaEnv= $_POST['fechaEnv'];

 if(isset($_POST['fechaEnv'])){
      //$fechaT = $fechaEnv;
      $fechaEnv= $_POST['fechaEnv']; 
      $output .= '<tr><td>Date should be displayed here: '.$fechaEnv.'</td></tr>';
    }

【讨论】:

  • 完全忘记了,非常感谢您的见解!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-05
  • 2016-11-04
  • 2020-03-27
相关资源
最近更新 更多