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
精彩评论