2013-10-23 201 views
0

我在我的網站上有一個表格http://www.team2457.us/contact_us/sponsorship.php。當我第一次填寫表格時,它工作正常,php腳本做了我想要的。但是現在每次我加載頁面時都會顯示一個彈出窗口,說明表格已成功完成,即使表格尚未加載完畢,我甚至沒有點擊過頂點按鈕。所以我想知道1)爲什麼它表現得像我打頂峯按鈕? 2)爲什麼表單通過驗證即時通訊使用?表格在頁面加載時提交空白並且頁面

這裏是我的代碼:

<!DOCTYPE HTML> 
<html> 
    <head> 
     <base href="http://www.team2457.us" > 
     <title>Team 2457 The Law</title> 
     <link rel="stylesheet" type="text/css" href="../styles/navstyle.css"> 
     <link rel="stylesheet" type="text/css" href="../styles/style.css"> 
     <style> 
      label { 
       display:block; 
       margin-top:20px; 
       letter-spacing:2px; 
      } 
      form { 
       margin:0 auto; 
       width:459px; 
      } 
      input, textarea { 
       width:439px; 
       height:27px; 
       background:#efefef; 
       border:1px solid #dedede; 
       padding:10px; 
       margin-top:3px; 
       font-size:0.9em; 
       color:#3a3a3a; 
       border-radius:5px; 
       -moz-border-radius:5px; 
       -webkit-border-radius:5px; 
      } 
      textarea { 
       height:213px; 
       background:#efefef; 
      } 
      input:focus, textarea:focus { 
       border:1px solid #97d6eb; 
      } 
      #submit { 
       width:127px; 
       height:38px; 
       background: #efefef; 
       border:none; 
       margin-top:20px; 
       cursor:pointer; 
      } 

     </style> 

    </head> 

    <body> 
     <div class="wrapper"> 
      <header id="banner"> 
       <img src="imgs/banner.png" align="center" alt="banner"/> 
      </header> 
      <nav> 
       <?php include '../nav.php'; ?> 
      </nav> 

      <section id="content"> 
       <?php 
        $name = $_POST['name']; 
        $email = $_POST['email']; 
        $message = $_POST['message']; 
        $from = 'From: potential sponsor'; 
        $to = '[email protected]'; 
        $subject = 'Sponsor'; 

        $body = "From: $name\n E-Mail: $email\n Message:\n $message"; 


        if (mail ($to, $subject, $body, $from)) { 
         echo '<script>alert("The form was completed succesfuly.");</script>'; 
         } 
        else { 
         echo '<script>alert("Something whent wrong, try again.");<script>'; 
         } 
       ?> 

       <form method="post" action="/contact_us/sponsorship.php"> 

        <label>Name</label> 
        <input name="name" placeholder="Type Here" value=""> 

        <label>Email</label> 
        <input name="email" type="email" placeholder="Type Here" value=""> 

        <label>Message</label> 
        <textarea name="message" placeholder="Type Here" value=""></textarea> 

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

       </form> 
      </section> 

      <footer> 

      </footer> 
     </div> 
    </body> 
</html> 
+0

您使用的驗證是什麼? – putvande

回答

0

您的郵件功能是被稱爲每次頁面加載。您應該考慮將處理$ _POST變量和郵件函數的PHP邏輯放在if(isset())函數中,如下所示:

if(isset($_POST["name"])){ 
    //Code to handle input validation and email sending goes here 
} 
+0

非常感謝,它非常完美! – luk3r0ck5

+0

很高興它爲你工作。 – jpodwys

+0

我正在爲我的高中機器人網站做這件事。所以我只是在學習。 – luk3r0ck5