簡體   English   中英

表單在頁面加載空白和PA上提交

[英]Form is submitted on page load blank and pa

我的網站上有一個表格,網址為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 = 'myemail@gmail.com'; 
                    $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>

每次頁面加載時都會調用您的郵件功能。 您應該考慮將處理$ _POST變量和mail函數的PHP邏輯放在if(isset())函數內,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM