【发布时间】:2017-01-09 18:37:44
【问题描述】:
更新:到目前为止,这是我的代码。现在出现了下载按钮,但代码正在打印表单结束标记,而不是将其标识为结束标记。我该如何纠正?请帮忙。提前致谢!!
<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>
$().ready(function() {
$(".datepicker").datepicker({dateFormat:'yy-mm-dd'});
});
</script>
</HEAD>
<BODY>
<center>
<h1>SAE Report</h1>
</center>
<form action = "" method = "post">
<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" class="datepicker" name="start">
<label>End Date</label><input type="text" class="datepicker" name="end">
<input type="submit" name="submit" value="Submit">
</form>
</BODY>
<?php
$type='';
$start='';
$end='';
if (isset($_POST['submit'])){
$type=$_POST['report'];
$start=$_POST['start'];
$end=$_POST['end'];
if ($type=="cumulative"){
echo "<form action='cumulativeRptExcel.php' method='post' name ='xls'>";
echo "<input type='submit' name='submitXLS' value='Download Excel'/>";
echo "/form><br>";
echo "<form action='cumulativeRptPDF.php' method='post' name ='xls'>";
echo "<input type='submit' name='submitXLS' value='Download PDF'/>";
echo "/form><br>";
}
elseif($type=='new' and $start!='' and $end!=''){
echo "<form action='newRptExcel.php' method='post' name ='xls'>";
echo "<input type='submit' name='submitXLS' value='Download Excel'/>";
echo "/form><br>";
echo "<form action='newRptPDF.php' method='post' name ='xls'>";
echo "<input type='submit' name='submitXLS' value='Download PDF'/>";
echo "/form><br>";
}
elseif($type="new" and ($start=='' or $end=='')){
echo "You need to select START and END date for the report";
}
}
?>
report.php 文件包含生成 excel 或 pdf 文件并使其可供用户下载的代码。当自己运行这些文件时,它会生成文件就好了。
【问题讨论】:
-
Using if(isset($_POST['submit'])) to not display echo when script is open is not working 的可能重复项(您必须为提交输入提供一个名称,以便使用
$_POST使其可用) -
这里更新了代码。但是现在 php 正在打印表单结束标记 (/form>) 而不是将其标识为结束标记。
-
这是个好消息,
if语句现在可以正常工作。/form>问题是因为您在 html 中缺少<。echo "/form><br>";应该是echo "</form><br>";
标签: php onsubmit submit-button webclient