【问题标题】:Submit Button won't appear提交按钮不会出现
【发布时间】: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&gt; 问题是因为您在 html 中缺少 &lt;。 echo "/form&gt;&lt;br&gt;"; 应该是 echo "&lt;/form&gt;&lt;br&gt;";

标签: php onsubmit submit-button webclient


【解决方案1】:

它会打印/form&gt;,因为根据您的代码,这就是您要求它打印的内容。你在我能看到的每一行中都回显了"/form&gt;&lt;br&gt;"; 而不是"&lt;/form&gt;&lt;br&gt;";。只需添加 &lt; 即可解决此问题

【讨论】:

    【解决方案2】:

    从以下位置更改您的提交按钮:

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

    到

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

    这背后的原因是 $_POST 变量只会包含在前一个表单中具有名称的元素。在您的示例中,提交按钮没有名称。

    【讨论】:

    • 哦,太好了,谢谢!!按钮正在显示,但现在它在屏幕上打印结束表单标记,而不是将其标识为结束标记。我该如何解决这个问题?
    • 替换回显 "/form>
      ";回声“
      ”;您缺少结束标记
    猜你喜欢
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 2014-06-12
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多