drt96856 2017-11-21 15:53
浏览 63

表单提交到PHP后禁用按钮

I want a PHP file to

A) disable submit button until page has been fully loaded and also while PHP script is actively running.

B) Allow a single PHP script to distinguish what form was submitted to it, so it can run different code for different form submissions.

C) Allow form to be submitted to any specified PHP script, whether it be an external file or a script on its own file.

<!DOCTYPE html>
<html lang = "en-US">
<head>
<title>Super Awesome Title!</title>
<meta charset = "UTF-8"/>

<?php
if(isset($_POST['SubmitButton']))
{
echo "Hello from PHP!";
}
?>

<script type = "text/javascript">
function disableSubmit1()
{
 document.getElementById("submitbutton_1").disabled = true;
}
</script> 

</head>
<body>

<form id="zipform" onsubmit="disableSubmit1()" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<input type="submit" id="submitbutton_1" name="SubmitButton" value="Test"/>
</form> 

</body>
</html>

Solved

I have found the solution to my problem. --> https://github.com/dougpurinton/disable_button_javascript/blob/master/disable_button_correct.php

  • 写回答

2条回答 默认 最新

  • donglin317704291 2017-11-21 15:59
    关注

    You must use Javascript / jQuery to do this just after the user presses the button.

    Using jQuery :

    $('#zipform').on('submit', function(e) {
        $('#submitbutton_1').attr('disabled', 'disabled');
    });
    

    This will make button disabled before page reloads, then using PHP after page reloads :

    <input type="submit" id="submitbutton_1" name="SubmitButton" value="Test"<?php echo (isset($_POST['SubmitButton']) ? ' disabled="disabled"': '') ?> />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思