Reputation: 199
ive got a form with 'from' and 'to' dates, which i use to query a DB. I want to display the results and fill in the date fields from the submitted query display the date fields
<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......
How do I get it to display the date in the posted variables
thanks
Upvotes: 1
Views: 67
Reputation: 1684
<?php
$from = (isset($_POST["from"]) && !empty($_POST["from"])) ? $_POST["from"] : '';
?>
<input type="text" id="from" name="from" value="<?php echo $from ?>" />
As in my exemple, with a ternary expression for your variables declarations, you can add easily a default value for your vars.
Upvotes: 0
Reputation: 4218
i'm not sure i get what you ask but this may be the answer you are looking for, since you post to the same page, you can show what you posted by echoing $_POST
variable into the value attribute of your form elements:
<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']; ?>"/>
Upvotes: 1