PHP 阻止一个人多次按“提交”


PHP Stopping a person pressing Submit multiple times

我有下面的形式,在表单之后,PHP 请求一个 Curl,这可能需要一段时间。正因为如此,他们一直按下提交按钮,认为什么都没发生。这会导致数据库中有多个条目。有人可以帮助我,让我知道该放什么来阻止这种情况。

我在第一个答案中尝试了Javascript解决方案,但它停止了随后的PHP脚本。不是我想要的。不好意思

<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <link href="css2/style.css" rel='stylesheet' type='text/css' />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
        <!--webfonts-->
        <link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text.css'/>
        <!--//webfonts-->
        <center><img class="displayed" src="images/logo.jpg" alt="Logo" style="width:128px;height:128px;"></center>
</head>
<body>
    <div class="main">
        <form action="" method="POST" enctype="multipart/form-data" id="contactform" >
      <input type="hidden" name="action" value="submit">
            <h1><span>Sign Up</span> <lable> The Brook on Sneydes</lable> </h1>
            <div class="inset">
                <p>
            <center><label ><?php echo $text; ?></label></center>
                        <label for="first">First Name</label>
                    <input type="text" name="first" id="first" value="" placeholder="" required/>
                </p>
                <p>
                        <label for="last">Surname</label>
                    <input type="text" name="last" id="last" value="" placeholder="" required/>
                </p>
        <p>
          <label for="mobile">Mobile Number</label>
          <input type="text" name="mobile" id="mobile" value="" placeholder="" required/>
      </p>
        <p>
          <label for="email">Email Address</label>
          <input type="text" name="email" id="email" value="" placeholder="" required/>
        </p>

       </div>
              <p class="p-container">
                <input type="submit" name="submit" id="submit" value="Submit">

              </p>
        </form>
    </div>
            <!-----start-copyright---->
                    <div class="copy-right">
                        <p> &copy; 2016 <a href="http://spearheaddigital.com.au/">Spearhead Digital</a>. All rights reserved.</p>
                    </div>
                <!-----//end-copyright---->
</body>
</html>
<?php
if(isset($_POST['submit']) && !empty($_POST) ){
$first = $_POST['first'];
$last = $_POST['last'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
// Other Code
}

您可以在提交表单时禁用提交按钮。

使用 jQuery 的示例:

<script type="text/javascript">
    $(document).ready(function() {
        $('#contactform').submit(function() {
            $('input[type=submit]', this).prop("disabled", true);
        });
    });
</script>