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

时间:2012-07-16 18:05:56

标签: javascript python forms cgi

我正在尝试使用python cgi和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> 

我无法确定表单数据是多次发送还是多次读取。但是,我认为没有理由在刷新时再次提交表单,所以我不得不相信它只是被多次阅读。以下是可以读取表单数据的组件:

# Create instance of FieldStorage 
form = cgi.FieldStorage()

if form.keys() != []:
  for x in form.keys():
    if x == 'send':
      send_email()

我尝试使用页面标记中的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>

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

0 个答案:

没有答案