开发者

Codeigniter: delete or change form button style

开发者 https://www.devze.com 2023-04-11 12:43 出处:网络
I\'m using Codeigniter to build a form. The submit button is: echo form_submit(开发者_开发技巧\'submit\', \'Buy it\', \"id=\'bred\'\");

I'm using Codeigniter to build a form.

The submit button is:

echo form_submit(开发者_开发技巧'submit', 'Buy it', "id='bred'");

Now I'm processing the form in the same php file that it is:

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

}

After inserting in the database I need to delete/change the css to opacity 0/change the css to display none the submit button, so the form cannot be submitted twice.

How can I do this?

Thanks


Except that the way you do isn't save: Due to "echo" the button you have no possibility to delete it with PHP

A (not very stylish) way would be to echo some JS code that deletes the button.


Making use of jQuery will make this easy for you.

You will need to detect the submission of the form and then disable the submit button.

This code assumes that your form and button have the IDs 'myForm' and 'submitButton' respectively.

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);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号