cgi脚本多次发送表单数据,每次刷新一次

2024-04-20 01:42:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pythoncgi和smtplib和imaplib编写自己的webmail应用程序。当我点击“发送”表单上的“发送”按钮时,邮件就会被发送,但是,每次刷新之后,邮件都会被再次发送。页面(cgi脚本)通过javascript每两分钟自动刷新一次:

  <script language="javascript">

    window.setInterval('refresh()', 180000);

    function refresh() 
    {
      // this checks to see which tab is selected, page is refreshed only if compose tab is not selected
      elList = document.getElementsByTagName("a");
      for (i = 0; i < elList.length; i++)
      { 
        if (elList[i].className === 'tab active') 
        {
          var activeTab = elList[i].innerHTML;
        }
      }

      if (activeTab.indexOf("Unread") >= 0)
      {
         window.location.reload(true);
      }

    } 
  </script> 

我真的不知道表单数据是多次发送还是多次读取。但是,我认为没有理由在刷新时再次提交表单,所以我不得不相信它只是被多次阅读而已。以下是启用表单数据读取的组件:

^{pr2}$

我试图在页眉标记中使用javascript重置表单,但没有成功:

<script language="javascript">
  Form.reset('send');  // reset send form so email is not sent again
</script>

为了完整起见,下面是表单定义:

  <form name="send" action="/cgi-bin/myemail.py" method="post" >
  <table id="example" class="compose" >
    <tr>
      <td><input type="submit" value="To:" style="height: 1.95em; width: 4em"></td><td><input type="text" name="send_to" size="90"></td><td><input type="submit" name="send" value="SEND" style="height: 1.95em; width: 12em"></td> 
    </tr>
    <tr>
      <td><input type="submit" value="Cc:" style="height: 1.95em; width: 4em"></td><td><input type="text" name="send_cc" size="90"></td> <td><input type="submit" name="send" value="SAVE" style="height: 1.95em; width: 12em"></td>
    </tr>
    <tr>
      <td><input type="submit" value="Bcc:" style="height: 1.95em; width: 4em"></td><td><input type="text" name="send_bcc" size="90"></td> <td><input type="submit" name="send" value="DELETE" style="height: 1.95em; width: 12em"></td>
    </tr>
    <tr>
      <td><input type="submit" value="Subj:" style="height: 1.95em; width: 4em"></td><td><input type="text" name="send_subj" size="90"></td> <td><input type="submit" name="send" size="200" value="ATTACH" style="height: 1.95em; width: 12em"></td> 
    </tr>
    <tr>
      <td colspan="3">
        <!-- <td colspan="3"> <div id="result" class="body" style="background-color:#000000"></div></td> -->
        <textarea name="send_body" cols="118" rows="23"> </textarea>
      </td>
    </tr>
  </table>
  </form>

如何防止此表单数据被多次读取?谢谢。在


Tags: namesend表单inputsizevaluestyletype