在php中获取datepicker输入值

时间:2017-01-03 06:06:50

标签: javascript php html datepicker get

我试图在php中获取字段值,但我似乎无法得到它们。尝试了post和get,没有结果。我知道它应该是一个简单的解决方案,但我只是看不出错误。任何帮助都很感激。谢谢!

这是我的report.html:

<HTML>
 <HEAD>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/style2.css">
  <TITLE>SAE Report</TITLE>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $(function() {
     $(".datepicker").datepicker({dateFormat:'yy-mm-dd'});
   });
  </script>

</HEAD>
<BODY>
<center>
<h1>SAE Report</h1>
</center>
 <form action = "report.php" method = "get">
 <label>Report Type</label>
    <select id="report">
        <option value="none"></option>
        <option value="new">New SAEs Report</option>
        <option value="cumulative">Cumulative SAE Report</option>
    </select>
 <label>Start Date</label><input type="text" class="datepicker" id='start' >
 <label>End Date</label><input type="text" class="datepicker" id='end'>
 <input type="submit" value="Submit" id ="submit">
 </form>
</BODY>

这是我的report.php:

<?php

$report=$_GET['report'];
   if ($report=="new"){
     $start=$_GET['start'];
     $end=$_GET['end'];
     echo 'Start date is:'.$start.' and end date is: '.$end;
   }
    else if ($report=="cumulative"){
     echo "print all SAEs";
   }    

?>

1 个答案:

答案 0 :(得分:2)

您在HTML中缺少name属性。只需添加它:

<form action = "report.php" method = "get">
    <label>Report Type</label>
    <select id="report" name="report">
        <option value="none"></option>
        <option value="new">New SAEs Report</option>
        <option value="cumulative">Cumulative SAE Report</option>
    </select>
    <label>Start Date</label><input type="text" name="start" class="datepicker" id='start' >
    <label>End Date</label><input type="text" name="end" class="datepicker" id='end'>
    <input type="submit" value="Submit" id ="submit">
</form>