我正在使用Codeigniter构建一个表单。
提交按钮为:
echo form_submit('submit', 'Buy it', "id='bred'");现在我在与表单相同的php文件中处理表单:
if (isset($_POST['submit'])) {
$query = "INSERT INTO table (product, price) VALUES ('$product', '$price')";
mysql_query($query)
or die(mysql_error());
//after inserting in the database I need to delete the submit button, so the form cannot be submitted twice
}在数据库中插入后,我需要删除/将css更改为不透明0/将css更改为不显示提交按钮,这样表单就不能提交两次。
我该怎么做呢?
谢谢
发布于 2011-10-05 23:30:27
使用jQuery会让这一切变得更容易。
您需要检测表单的提交,然后禁用submit按钮。
这段代码假设您的窗体和按钮分别具有ID 'myForm‘和'submitButton’。
Javascript:
// Detect the submission of myForm
$('form#myForm').bind('submit', function() {
// Disable the submit button and fade to half opacity
$('input#submitButton').attr("DISABLED", true).fadeTo('fast', 0.5);
});发布于 2011-10-05 23:26:41
除了你做的方式不是保存:由于“回显”按钮,你不可能删除它与PHP
一种(不太时髦的)方法是回显一些删除按钮的JS代码。
https://stackoverflow.com/questions/7663679
复制相似问题