[eluser]gwerner[/eluser]
I think what everyone is saying makes sense. Below is my updated code. This still doesn't prevent someone from just typing in the browser the link with an invalid id. If the user does they will simply receive a blank page. I could use a redirect for this, but maybe I'm missing something here? (And, I still haven't taken into consideration non-javascript users.)
Delete Link
Code:
<a class="delete" href="/newaccess/users/remove/<?php echo $value['users_slug']; ?>">Delete</a>
Controller - The user would actually be routing though the index method in my controller. The index method simple creates a list view of all users at this point. This view provides a delete link per row for each user. The controller below would only be accessed if the delete link is clicked.
Code:
// remove users controller
public function remove($userId)
{
$this->data = $this->users_model->remove_users($userId);
}
Model
Code:
function remove_users($id)
{
$table = $this->get_table();
$this->db->where('users_id', $id);
$this->db->delete($table);
if ($this->db->affected_rows() > 0)
{
$response['status'] = 'success';
$this->output->set_output(json_encode($response_array));
} else {
$response['status'] = 'error';
$this->output->set_output(json_encode($response_array));
}
}
Ajax
Code:
$.ajax({
type: 'post',
url: '/newaccess/users/remove/' + parent.attr('id').replace('record-',''),
dataType: 'json',
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function(results) {
if(results.status == 'success') {
parent.hide(300,function() {
parent.remove();
});
}
else if(results.status == 'error') {
parent.animate({'backgroundColor':'#ffde00'},300);
}
}
}); // end ajax