简体   繁体   English

提交和页面刷新后禁用提交按钮

[英]Disable submit button after submit and page refresh

What i want is pretty simple, i have a button that submits a value to my database once clicked, what i need is to diable the button parmanently after value has been submited, i have searched and the codes i have seen all enable the button when the page refreshes.. please can someone help me out? 我想要的是非常简单的,我有一个按钮,一旦单击它就向我的数据库提交一个值,我需要的是在值提交后永久地禁用该按钮,我已经搜索过并且我看到的代码都在启用该按钮时页面刷新..请有人帮帮我吗?

My form and button code as follows: 我的表单和按钮代码如下:

<form action="<?php echo $editFormAction; ?>" method="POST" name="Status2" id="Status2" onSubmit="return confirm('Are you sure you want to submit?');">
      <input name="Confirm2" type="checkbox" id="Confirm2" value="Confirmed" checked="CHECKED" style="display:none;">
      <label for="Confirm2"></label>
      <input name="UpdateButton3" type="submit" class="art-button" id="UpdateButton3" value="Confirm"/>
      <input name="UserIDHiddenField4" type="hidden" id="UserIDHiddenField4" value="<?php echo $row_User['UserID']; ?>">
      <input name="Purge2" type="checkbox" id="Purge2" value="You Will Be Rematched Soon!" checked="CHECKED" style="display:none;">
      <label for="Purge2"></label>
      <input type="hidden" name="MM_update" value="Status2">
    </form>

First of all if you submit it, this has nothing to do with javascript. 首先,如果您提交它,则与javascript无关。 Save this in your database as @georoot says. 按照@georoot的说明将其保存在数据库中。 Then when you submit, save a value in the database. 然后,当您提交时,将值保存在数据库中。 If that value is set, you can disable the button by just HTML: <input type="submit" <?php if($valueFromDatabase==1){ ?> disabled <?php } ?> > 如果设置了该值,则可以通过HTML禁用按钮: <input type="submit" <?php if($valueFromDatabase==1){ ?> disabled <?php } ?> >

Best solution could be to set a cookie on client system and/or get user IP and save it into your database, but you should keep in mind, non of them are permanent ! 最好的解决方案是在客户端系统上设置cookie和/或获取用户IP并将其保存到数据库中,但是请记住,它们都不是永久的! The IP can be changed and the cookie can be removed ! 可以更改IP并删除Cookie! But you can use both cookie and IP check. 但是您可以同时使用cookie和IP检查。

Then for each page load, just check if cookie exist (compare the value with ur database value) and/or client IP is already exist in database. 然后,对于每次页面加载,只需检查cookie是否存在(将值与ur数据库值进行比较)和/或数据库中是否已存在客户端IP。

Or if you know who is on the page (if it's a logged user) just add a field in your database and set value = 1 or = 0 and check the field each time it's loaded for same field and for same user. 或者,如果您知道页面上的用户(如果是登录用户),则只需在数据库中添加一个字段,并将值设置为1或= 0,并在每次加载该字段时为同一字段和同一用户检查该字段。

I wouldn't recommend to use IP check without cookies ! 我不建议您在没有Cookie的情况下使用IP检查! Because it can change frequency ! 因为它可以改变频率!

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

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