2011-10-05 46 views
0

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

我该怎么做?

感谢

+0

你为什么不处理在控制器的形式? –

+1

您正在查询没有框架的方法,但使用旧的mysql_ *函数,而不是在模型中,除了在控制器之外处理表单。还有什么? –

回答

0

使用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); 
}); 
1

除非你做的方式是无法保存: 由于“回声”你有没有可能用PHP

一个删除它(不是很时尚)的方式将是按钮来回显一些删除按钮的JS代码。

+0

在JS中这将如何呢?一直在尝试很多,但没有任何影响按钮..我疯了 – user523129