Codeigniter:删除或更改表单按钮样式


Codeigniter: delete or change form button style

我正在使用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以显示无提交按钮,因此表单不能提交两次。

我该怎么做?

谢谢

除了你不保存的方式:由于"echo"按钮,你无法用PHP删除它

一种(不是很时尚的)方法是回显一些JS代码来删除按钮。

使用jQuery将使这一切变得容易。

您需要检测表单的提交,然后禁用提交按钮。

这段代码假设表单和按钮的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);
});