【问题标题】:Codeigniter: delete or change form button styleCodeigniter:删除或更改表单按钮样式
【发布时间】:2011-12-01 14:19:31
【问题描述】:

我正在使用 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更改为opacity 0/更改css以不显示提交按钮,因此表单无法提交两次。

我该怎么做?

谢谢

【问题讨论】:

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

标签: php css forms codeigniter submit


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    除了你不保存的方式: 由于“回显”按钮,您无法使用 PHP 删除它

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

    【讨论】:

    • 在 JS 中怎么会这样?尝试了很多,但没有任何影响按钮..我要疯了
    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 2021-05-03
    相关资源
    最近更新 更多