Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 过帐表单后重置隐藏变量_Php_Javascript_Html - Fatal编程技术网

Php 过帐表单后重置隐藏变量

Php 过帐表单后重置隐藏变量,php,javascript,html,Php,Javascript,Html,我想把搜索条件输出的记录下载到excel。 因为搜索条件的字段超过20个。我用POST方法提交表格,而不是GET 单击“Download2excel”,隐藏变量name1设置为Yes。因此,我将检查代码中的条件。下载成功后,我想重置变量 下面是我的代码的示例结构 <html> <head> <?php if(trim($_POST['name1']) == 'yes') { header("Co

我想把搜索条件输出的记录下载到excel。 因为搜索条件的字段超过20个。我用POST方法提交表格,而不是GET

单击“Download2excel”,隐藏变量name1设置为Yes。因此,我将检查代码中的条件。下载成功后,我想重置变量

下面是我的代码的示例结构

    <html>
    <head>
        <?php
        if(trim($_POST['name1']) == 'yes') {
            header("Content-type: application/vnd-ms-excel");
            header("Content-Disposition: attachment; filename=$filename.xls");
        }else {
            ?>
    </head>
    <body onload="tempFn()">

        <script language="javascript" type="text/javascript">
            function tempFn(){  
                global_search.name1.value = "";
            }
            function gs_download2xl_c() {
                document.getElementById('name1').value="yes";
                document.global_search.submit();
            }
        </script>
        <form name="global_search" id="global_search" action="test_1.php" method="POST">
            <input type="text" id="name1" name="name1" />
            <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
                Download2excel
            </a>
        </form>
            <?php } ?>
    </body>
</html>

函数tempFn(){
global_search.name1.value=“”;
}
函数gs_下载2xl_c(){
document.getElementById('name1')。value=“是”;
document.global_search.submit();
}
下载2Excel
由于我在发布表单后没有执行表单,因此无法访问其中的变量name1。我想重置变量名1

请给我建议一个更好的程序

编辑:-


我想在提交表单后触发下载。因为下载到excel的记录应符合输入搜索条件

编辑:基于编辑的问题的新答案 为了做您想要做的事情,您需要使用GET变量并生成一个新窗口
范例
  if( isset($_GET['name1']) ) // if the field is set then we are receiving the form fields
  {
        //Process Fields here


        //Send file here
        header("Content-type: application/vnd-ms-excel");
        header("Content-Disposition: attachment; filename=$filename.xls");
        $handle = fopen("filename","r");
        echo fread($handle,filesize($filename.".xls"));
        fclose($handle);
        die; //We kill the script here so it doesnt try to print the rest of the file
    }

?>
<script language="javascript" type="text/javascript">
    function gs_download2xl_c() {
        //get fields
        var Query = new Array();
        Query.push( "name="+document.getElementById("name1") );

        url = "test_1.php?"+Query.join("&");
        window.open(url);
        document.getElementById("global_search").reset();
    }
</script>
<form name="global_search" id="global_search" action="test_1.php" method="POST">
    <input type="text" id="name1" name="name1" />
    <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
        Download2excel
    </a>
</form>
if(isset($\u GET['name1'])//如果设置了字段,则我们将接收表单字段
{
//这里的进程字段
//在这里发送文件
标题(“内容类型:应用程序/vnd ms excel”);
标题(“内容处置:附件;文件名=$filename.xls”);
$handle=fopen(“文件名”、“r”);
echo-fread($handle,filesize($filename..xls”);
fclose($handle);
die;//我们在这里终止脚本,这样它就不会试图打印文件的其余部分
}
?>
函数gs_下载2xl_c(){
//获取字段
var Query=新数组();
Query.push(“name=”+document.getElementById(“name1”);
url=“test_1.php?”+Query.join(“&”);
窗口打开(url);
document.getElementById(“全局搜索”).reset();
}
下载2Excel

编辑:基于编辑的问题的新答案 为了做您想要做的事情,您需要使用GET变量并生成一个新窗口
范例
  if( isset($_GET['name1']) ) // if the field is set then we are receiving the form fields
  {
        //Process Fields here


        //Send file here
        header("Content-type: application/vnd-ms-excel");
        header("Content-Disposition: attachment; filename=$filename.xls");
        $handle = fopen("filename","r");
        echo fread($handle,filesize($filename.".xls"));
        fclose($handle);
        die; //We kill the script here so it doesnt try to print the rest of the file
    }

?>
<script language="javascript" type="text/javascript">
    function gs_download2xl_c() {
        //get fields
        var Query = new Array();
        Query.push( "name="+document.getElementById("name1") );

        url = "test_1.php?"+Query.join("&");
        window.open(url);
        document.getElementById("global_search").reset();
    }
</script>
<form name="global_search" id="global_search" action="test_1.php" method="POST">
    <input type="text" id="name1" name="name1" />
    <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
        Download2excel
    </a>
</form>
if(isset($\u GET['name1'])//如果设置了字段,则我们将接收表单字段
{
//这里的进程字段
//在这里发送文件
标题(“内容类型:应用程序/vnd ms excel”);
标题(“内容处置:附件;文件名=$filename.xls”);
$handle=fopen(“文件名”、“r”);
echo-fread($handle,filesize($filename..xls”);
fclose($handle);
die;//我们在这里终止脚本,这样它就不会试图打印文件的其余部分
}
?>
函数gs_下载2xl_c(){
//获取字段
var Query=新数组();
Query.push(“name=”+document.getElementById(“name1”);
url=“test_1.php?”+Query.join(“&”);
窗口打开(url);
document.getElementById(“全局搜索”).reset();
}
下载2Excel

我似乎不太明白你的问题。但我肯定会提出一些建议:

  • 标题(…)
    应在将任何输出发送到浏览器之前显示。这意味着您必须在任何其他输出行之前移动该行。检查
  • 请尝试以下操作:

    <script>
    function tempFn(){
        global_search.name1.value = "";
    }
    </script>
    <body onload="tempFn()">
    </body>
    
    编辑2 不标记“外部”的每个字符都“输出”到浏览器。在您的情况下,
    将进入浏览器。然后在PHP脚本中设置内容类型,这是不正确的。 请尝试以下方法:

     <?php
        if(trim($_POST['name1']) == 'yes') {
            header("Content-type: application/vnd-ms-excel");
            header("Content-Disposition: attachment; filename=$filename.xls");
        }else {
            ?>
    <html>
    <head>
        <script language="javascript" type="text/javascript">
            function tempFn(){  
                global_search.name1.value = "";
            }
            function gs_download2xl_c() {
                document.getElementById('name1').value="yes";
                document.global_search.submit();
            }
        </script>
    </head>
    <body onload="tempFn()">
        <form name="global_search" id="global_search" action="test_1.php" method="POST">
            <input type="text" id="name1" name="name1" />
            <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
                Download2excel
            </a>
        </form>
            <?php } ?>
    </body>
    </html>
    
    
    函数tempFn(){
    global_search.name1.value=“”;
    }
    函数gs_下载2xl_c(){
    document.getElementById('name1')。value=“是”;
    document.global_search.submit();
    }
    下载2Excel
    
    我似乎不太明白你的问题。但我肯定会提出一些建议:

    • 标题(…)
      应在将任何输出发送到浏览器之前显示。这意味着您必须在任何其他输出行之前移动该行。检查
    • 请尝试以下操作:

      <script>
      function tempFn(){
          global_search.name1.value = "";
      }
      </script>
      <body onload="tempFn()">
      </body>
      
      编辑2 不标记“外部”的每个字符都“输出”到浏览器。在您的情况下,
      将进入浏览器。然后在PHP脚本中设置内容类型,这是不正确的。 请尝试以下方法:

       <?php
          if(trim($_POST['name1']) == 'yes') {
              header("Content-type: application/vnd-ms-excel");
              header("Content-Disposition: attachment; filename=$filename.xls");
          }else {
              ?>
      <html>
      <head>
          <script language="javascript" type="text/javascript">
              function tempFn(){  
                  global_search.name1.value = "";
              }
              function gs_download2xl_c() {
                  document.getElementById('name1').value="yes";
                  document.global_search.submit();
              }
          </script>
      </head>
      <body onload="tempFn()">
          <form name="global_search" id="global_search" action="test_1.php" method="POST">
              <input type="text" id="name1" name="name1" />
              <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
                  Download2excel
              </a>
          </form>
              <?php } ?>
      </body>
      </html>
      
      
      函数tempFn(){
      global_search.name1.value=“”;
      }
      函数gs_下载2xl_c(){
      document.getElementById('name1')。value=“是”;
      document.global_search.submit();
      }
      下载2Excel
      
      是的,我误解了你的问题,重新考虑了应该怎么做。编辑:其实还没有完全理解。。。您是在尝试触发下载,还是也需要提交信息,因为name1字段除了触发看起来像是下载开始的内容之外没有任何真正的用途谢谢您的尝试。但是我执行了上面的代码。第一次单击download2excel时,什么都没有发生。第二次下载到excel对话框即将到来。但是变量的值仍然是相同的。它没有重置。是的,我误解了你的问题,重新编辑了应该如何工作。编辑:其实还没有完全理解。。。您是在尝试触发下载,还是也需要提交信息,因为name1字段除了触发看起来像是下载开始的内容之外没有任何真正的用途谢谢您的尝试。但是我执行了上面的代码。第一次单击download2excel时,什么都没有发生。第二次下载到ex