开发者

Delete button instead of a link

开发者 https://www.devze.com 2023-03-31 06:02 出处:网络
I want to delete something from my DB when the delete button is clicked. So far I have a link to delete information from my DB, but 开发者_C百科I want to display a button instead of a link.

I want to delete something from my DB when the delete button is clicked. So far I have a link to delete information from my DB, but 开发者_C百科I want to display a button instead of a link.

I don't understand how to implement a submit button in the following code.

<p>
    <?php echo anchor('del_controller/del/'. $id, 'Delete', array('onClick' =>   "return confirm('Are you sure you want to delete?')"));?>
</p>


You want to use the form_submit()-function instead:

<?php echo form_submit('mysubmit', 'Submit Post!'); ?>

As read in the documentation:

Similar to other functions, you can submit an associative array in the first parameter if you prefer to set your own attributes. The third parameter lets you add extra data to your form, like JavaScript.

So, getting the result you want you would probably have to write:

$data = array(
    'name'        => "submit",
    'value'       => "Delete",
    'onClick'     => "return confirm('Are you sure you want to delete?');"
);
echo form_submit($data); 

The path to POST the form to is set when opening the form.

echo form_open('del_controller/del/'. $id);

Read more at http://codeigniter.com/user_guide/helpers/form_helper.html

0

精彩评论

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