Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:13:45+00:00 2026-06-11T03:13:45+00:00

I have working codeigniter controller and view which sucessfully delete record. I would like

  • 0

I have working codeigniter controller and view which sucessfully delete record. I would like to do it with ajax – jquery, to avoid reloading the page, and sure enough I will need to prompt the user if he is sure about deleting the record.

Any code snippet would be deeply appreciated, since i don’t know where to start:

Here is the code from the controller:

public function deleteUser()
    {
        $this->load->model('backOfficeUsersModel');
        $deleteWhat = array(
            'dpage' => $this->input->post('dpage'),
            'rid'   => $this->input->post('rid')
        );
        $this->backOfficeUsersModel->delete($deleteWhat['rid']);
        redirect($deleteWhat['dpage']);
    } // end of function deleteUser

Here is the view that I have now: (just the php code is presented for the sake of simplicity)

foreach ($users as $key => $user) {
                            echo form_open('backOfficeUsers/deleteUser');
                            echo form_hidden('dpage', 'backOfficeUsers/displayAllUsers');
                            echo form_hidden('rid', $user['userid']);
                            echo "<tr>";
                            echo "<td>";

                            $data = array(
                                'name' => 'row_sel',
                                'id' => $user['userid'],
                                'value' => $user['userid'],
                                'class' => 'select_row'
                            );

                            echo form_checkbox($data);

                            //echo "<input type='checkbox' class='select_row' name='row_sel'>"; 
                            echo "</td>";
                            echo "<td>" . $user['userid'] . "</td>";
                            echo "<td>" . $user['firstname'] . " " . $user['lastname'] . "</td>  ";
                            echo "<td>" . $user['username'] . "</td>  ";
                            echo "<td><a href=mailto:" . $user['email'] . ">" . $user['email'] . "</td>  ";
                            echo "<td style='text-align: center;'>";
                            echo anchor("backOfficeUsers/displayEditUserForm/$user[userid]/", "<i class=splashy-pencil></i>", "class=ext_disabled");     
                            echo "</td>";
                            echo"<td style='text-align: center;'>";
                            $confirm = "class='splashy-remove' style='border:none; width:16px; height:16px;'";

                            echo form_submit('submit', '', $confirm);
                            echo"</td></tr>";

                            echo form_close();
                        }

Any help (code snippet, or link to some example) will be deeply appreciated

Regards,Zoran

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:13:46+00:00Added an answer on June 11, 2026 at 3:13 am

    Please, go easy on the echo statements. If you find yourself using them excessively it probably because you should be writing HTML with embedded PHP and not PHP with embedded HTML. Also, when posting questions on SO, remove the extra fluff that only serves to confuse answerers. There is a lot of crap in your code that does not get to the heart of your problem.

    From scratch, here’s the HTML scaffolding I’d use:

    <table>
        <thead>
            <tr>
                <th>Username</th>
                <th>Actions</th>
            </tr>
        </thead>
    <tbody>
        <? foreach($users as $uK => $uV):?>
            <tr>
                <td><?= $uV['username']?></td>
                <td><a class='deleteUser' href='backOfficeUsers/deleteUser/<?= $uV["id"]?>'>Delete</a></td>
            </tr>        
        <? endforeach;?>
    </tbody>
    

    Then the jQuery:

    <script type='text/javascript'>
        $(document).ready(function(){
            $(".deleteUser").click(function(e){
                $this  = $(this);
                e.preventDefault();
                var url = $(this).attr("href");
                $.get(url, function(r){
                    if(r.success){
                        $this.closest("tr").remove();
                    }
                })
            });
        });
    </script>
    

    And the controller:

    class Backofficeuser extends CI_Controller{
        function __construct(){
            ...
        }
    
        function deleteUser($id){
            $u = new User($id);
            if($u->delete()) return json_encode(array("success" => true));            
        }
    
    }
    

    I used Datamapper’s syntax here for record deletion, please adapt to Active Record. The code is not tested, it was written here in the SO editor – but it is how I would go about things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m using codeigniter and would like to grab some user info with ajax.
I'm using CodeIgniter for a project I'm working on. I have an ajax call
I'm working on a Facebook-like status update using jquery in Codeigniter. So far, I've
I have phonegap and jquery mobile working properly and am trying to add codeigniter
I have a codeigniter code that is working on local Apache installation. But it
I'm working on upgrading a Codeigniter app I have running on 1.7.2 to 2.0.3
I'm working on an app in CodeIgniter, and I want to have admin pages
I have working website in PHP with a MySQL backend which has several tables
I have a third party library which I finally have working within my MonoTouch
Okay so, I'm working with CodeIgniter. posts.php is my view that displays all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.