php - 操作完成后禁用提交表单

标签 php javascript jquery mysql

好吧,我已经疯狂了几个小时试图解决这个问题......

我希望我的表单在单击后被禁用,这样就不会发生多次提交。但是,当我尝试禁用它的方法时......我已经尝试了很多方法,它会在单击按钮后禁用它,但它会停止表单应该执行的所有功能。例如,将其添加到我的代码中会在单击表单后禁用该表单,但会停止所有功能。

onclick="this.disabled=true;this.value='Sending, please wait...';this.form.submit();"

这是我的表格

<form name="input" action="" method="post" id="id">
  <div align="center">
    <input name="Submit" id="Submit" type="submit" class="button" value="Explore Map!"/>
  </div>
</form> 

这是单击表单时应该发生的情况(我知道代码很糟糕且不安全,但它有效,这正是我所需要的。)

if (isset($_POST['Submit'])) {

include 'includes/mapstuff.php';

// Ok so we called the submit button sbubmit and the method is post so

// So here we pick a random row from the table pokemon notice the order by rand
$sql23 = "SELECT * FROM map1pokemon ORDER BY RAND() LIMIT 1;";
// We then check for errors
$result23 = mysql_query($sql23) or die(mysql_error());
// we then make the result into a virable called battle_get23
$battle_get23 = mysql_fetch_array($result23);

$sql2 = "SELECT * FROM pokemon WHERE name='".$battle_get23['pokemon']."'";
$result2 = mysql_query($sql2) or die(mysql_error());
$battle_get2 = mysql_fetch_array($result2);

// Now we need to make sure the image is safe be for we use it
$pic2= mysql_real_escape_string($battle_get2['pic']);
$pic = strip_tags($pic2);


include 'includes/maptypes.php';


?>


<form name="inputt" action="" method="post">
  <div align="center">
    <input type="submit" class="catch" value="Catch Pokemon" name="catch">
  </div>
</form> 
<p></p>

<?php
echo "You have just found a " ;
echo $randomview[0];
echo " ";

// we can now print off any column we want about the random pokemon e.g the name the pic etc... here I chose to print out the name.but th
echo $battle_get23['pokemon'];


$_SESSION['pokemon'] = $battle_get23['pokemon']; 
$_SESSION['type'] = $randomview[0];
$_SESSION['pic'] = $battle_get2;
$_SESSION['money'] = $randomview2[0];
$_SESSION['level'] = $randomview3[0];
$_SESSION['ticket'] = $randomview4;

?>
<p></p>
<?php
echo "You have gained ".$randomview3[0]." levels" ;
echo " ";
?>
<p></p>
<?php
echo "You have received $".$randomview2[0]."" ;
echo " ";
?>
<p></p>
<?php
echo "</center>";
}

?>

最佳答案

使用 Jquery

$("form").submit(function() {
    $(this).submit(function() {
        return false;
    });
    return true;
});

Refer this Question

关于php - 操作完成后禁用提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15716228/

相关文章:

javascript - 如何获取我们在谷歌地图中放置街景小人的点的坐标

php - 在 PHP (plphp) 中,我们如何使用 Imagick 管理存储在 bytea 中的文件?

javascript - 增加 d3 可折叠树上线/节点之间的空间

javascript - Google map 上重叠标记的合并工具提示

jQuery 在 asp net core 2 razor 中设置日期值

javascript - 如何使用 jquery 将数据属性附加到类

php - 使用 mysqli 转义字符串转义数组

php - 特殊字符如 č,š,ž 从 php 到 android TextView

php - Codeigniter - 如果用户在数据库中创建了条目,则仅允许用户从数据库中删除

javascript - 在表行中选中复选框时启用文本框