禁用用户输入php / html表单

时间:2013-01-22 12:18:07

标签: php

我有一个HTML表单,当用户点击提交时,所有信息都会通过php脚本使用POST方法发送到电子邮件。我想要做的是在单击提交按钮后禁用所有用户输入或灰显所有文本框输入字段。我该怎么做呢?

此刻提交按钮的代码如下所示:

<input type="submit" value=" Continue " style="width:200px;height:40px">

5 个答案:

答案 0 :(得分:0)

使用jQuery:$("input").prop('disabled', true); 但是在没有刷新页面的情况下,纯粹的Html是不可能的!

编辑: Javascript:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(e) {
    $("#yourFormID").submit(function() {
        $("#theInputToDisable").prop('disabled', true);
        //Or to disable all inputs 
        //$(this).children("input").prop('disabled', true);
        //$(this).children("input").attr('disabled', 'disabled'); 
        return false;
    })
});
</script>

<强> HTML

<form id="yourFormID">
    <input type="text" />
    <input type="submit" value="Send"/>
</form>

答案 1 :(得分:0)

在下面添加您要禁用的每个HTML输入元素。既然你没有提到我假设你可以使用PHP。

<?php if(isset($_POST['submit'])) echo 'disabled="disabled"'; ?>

如果您正在使用AJAX,则在特定事件

内触发事件时
$("input").prop('disabled', true);

答案 2 :(得分:0)

单击“提交”按钮可将所有输入设置为禁用

$("input").attr('disabled', true);

答案 3 :(得分:0)

没有数据库交互你不能这样做,在db表中有一个标志。如果用户提交表单,则设置标志1,默认为0.根据标志值,您可以禁用表单。

if(mailsent_status_of_the_user == 1){
    $status = "disabled='disabled'";
}else{
   $status = "";
}



<input type="submit" value=" Continue " <?php echo $status; ?> >

答案 4 :(得分:0)

由于邮件是否已经发送是服务器端处理,如果你从服务器端处理它比从jQuery和javascript客户端处理它更好:

$form_state = ($is_mail_sent)?"":"disabled='disabled'";

<input type="submit" <?php echo $form_state ?> value=" Continue " style="width:200px;height:40px">