2017-01-09 80 views
0

更新:到目前爲止,這是我的代碼。下載按鈕現在出現,但代碼打印表單結束標籤,而不是將其標識爲結束標籤。我該如何解決這個問題?請幫忙。提前致謝!!提交按鈕不會出現

<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文件並使其下載到用戶。當它們自己運行這些文件時,它會生成文件。

<input type="submit" value="Submit"> 

<input type="submit" name="submit" value="Submit"> 

這背後的原因是$ _ POST變量只會有過前面的表格,裏面的名稱元素:

+0

可能重複[使用if(isset($ \ _ POST \ ['submit'\]))在腳本打開時不顯示回顯不工作](http://stackoverflow.com/questions/7775512/using-ifisset-postsubmit-to-not-display-echo-when-script-is-open-is-not)(你必須給你的提交輸入一個名字,使它可以使用'$ _POST ') – JNevill

+0

這裏更新了代碼。但現在,PHP正在打印表單結束標記(/ form>),而不是將其標識爲結束標記。 –

+0

這是'if'語句現在正常工作的好消息。 '/ form>'問題是因爲你在你的html中缺少'<'。 'echo「/ form>
」;'應該是'echo'
「;' – JNevill

回答

0

它打印/form>,因爲從您的代碼,這是你要求它打印。你可以在每行中看到"/form><br>";而不是"</form><br>";。只需添加<即可修復該問題

0

從改變你的提交按鈕。在你的例子中,提交按鈕沒有名字。

+0

哦,不錯,謝謝!按鈕正在顯示,但現在它在屏幕上打印結束標籤,而不是將其標識爲結束標籤。我怎樣才能解決這個問題? –

+0

替換回聲「/ form>
」;用於回聲「
」;您缺少結束標籤 –