我有一个带有'from'和'to'日期的表单,用于查询数据库。我想显示结果并从提交的查询中填写日期字段,显示日期字段
<form action="<?php print $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="uid" value="<?php echo $uid ;?>"
<label for="from">FROM</label> <input type="text" id="from" name="from"/>
<label for="to">TO</label> <input type="text" id="to" name="to"/>
<input type="submit" value="Submit" />
<script type="text/javascript">
$(function() {
$( "#from").datepicker({
showOn: "button",buttonImage: "jquery/images/calendar.gif",
buttonImageOnly: true,changeMonth: true, dateFormat: 'yy-mm-dd',
onSelect: function( selectedDate ) {
var dateMin = $('#from').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 1);
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 365);
$('#to').datepicker("option","minDate",rMin);$('#to').datepicker("option","maxDate",rMax); }
});
$( "#to" ).datepicker({
showOn: "button",
buttonImage: "jquery/images/calendar.gif",
buttonImageOnly: true,defaultDate: "+1w",
changeMonth: true,
dateFormat: 'yy-mm-dd'
});
});
</script>
and then
if (isset($_REQUEST['to']))
{
print '<script language="javascript" type="text/javascript">';
print '$("#from").datepicker("setDate","'.$_REQUEST['to'].'")';
print '</script>';print "\n";
$sql ="SELECT blah blah blah......
如何让它在发布的变量中显示日期
谢谢
答案 0 :(得分:1)
我不确定我得到了你的要求,但这可能是你要找的答案,因为你发布到同一页面,你可以通过回显$_POST
变量到值属性来显示你发布的内容您的表单元素:
<label for="from">FROM</label> <input type="text" id="from" name="from" value="<?php echo $_POST['from']; ?>"/>
<label for="to">TO</label> <input type="text" id="to" name="to" value="<?php echo $_POST['to']; ?>"/>
答案 1 :(得分:0)
<?php
$from = (isset($_POST["from"]) && !empty($_POST["from"])) ? $_POST["from"] : '';
?>
<input type="text" id="from" name="from" value="<?php echo $from ?>" />
在我的例子中,使用变量声明的三元表达式,您可以轻松添加变量的默认值。