简体   繁体   English

防止重复提交

[英]Prevent Double Submission

i have a project on PHP, MySQL and using the CodeIgniter Framework, i have a page where the user submits an order, but the problem is that it takes a while for the system to process it and in the meantime if the user presses the submit button it will be submitted again.我有一个关于 PHP、MySQL 和使用 CodeIgniter 框架的项目,我有一个用户提交订单的页面,但问题是系统需要一段时间来处理它,同时如果用户按下提交按钮,它将再次提交。

What i am trying to do is to disable the button once it is pressed.我想要做的是在按下按钮后禁用该按钮。 Here is the button code这是按钮代码

<div class="row">
    <div class="col-md-7">
        <!-- begin panel -->
             <input type="hidden" name="order_status" value="0" />
                <button  type="submit" class="btn btn-success saveit saveorderf_"><?php echo "Save";?></button>
        <!-- end panel -->
    </div>
</div>

What i have tried so far is using the到目前为止我尝试过的是使用

onClick="this.disabled=true;

but it only disables the button with out the form being submitted.但它只会在没有提交表单的情况下禁用按钮。

Any ideas what i might be missing here .任何我在这里可能会遗漏的想法。

Thanks in advance.提前致谢。

You can replace your code with this:你可以用这个替换你的代码:

onclick="this.disabled = true; form.submit();"

the form.submit(); form.submit(); will do the job for you会为你做这项工作

You can disable the button after form is submitted.您可以在提交表单后禁用该按钮。

reference: Simplest way to disable button on submission of a form?参考: 在提交表单时禁用按钮的最简单方法?

 $(document).ready(function(){ $('.once-only').submit(function(){ $(this).children('button').prop('disabled', true); }); });
 <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script> <form method="POST" class="once-only"> <input type="text" name="q"/> <button >Send</button> </form>

working jsfiddle: http://jsfiddle.net/gKFLG/1/工作jsfiddle: http : //jsfiddle.net/gKFLG/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM