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

  • SEARCH
  • Home
  • 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 8116651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:53:54+00:00 2026-06-06T03:53:54+00:00

In my table I have a column with a check box for each row.

  • 0

In my table I have a column with a check box for each row. I want to be able to delete all the selected items. I found the code from this website and modified it for my own stuff.
Link

I followed the website’s naming convention for the check boxes and it is as follows:

<td>  <?php echo $this->Form->checkbox('LocalClocks.id.['.$LocalClock['LocalClock']['id'].']', array('value' => $LocalClock['LocalClock']['id'])); ?></td>

This is the code in my controller for the deleteSelected() function:

    public function deleteSelected()
    {
        foreach($this->data['LocalClocks'] as $key => $value)
        {
            if($value != 0)
            {
                $this->LocalClock->del($value);
            }
        }
        $this->redirect($this->referer());
    }

This is the code for the actual delete button (just in case it is needed):

<?php echo $this->Form->postLink('Delete Selected', array('action' => 'deleteSelected'), array('confirm' => 'Are you sure?')); ?>

There are a couple things I think might be the problem:

  1. The code was written for an older version of cake, I think the website said 1.3, but I don’t know what to update/correct in the existing code to make it work.
  2. The delete button is the same as the one on cakephp’s website on the blog tutorial. The only change I made was removing the id of the item to delete, because im not deleting a single item but multiple items.

Any help would be great.

  • 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-06T03:53:55+00:00Added an answer on June 6, 2026 at 3:53 am

    Your checkbox input should be something like this

    echo $this->Form->checkbox('LocalClocks.'.$LocalClock['LocalClock']['id'], array(
      'value' => $LocalClock['LocalClock']['id'],
      'hiddenField' => false
    ));
    

    This will create a data array that will look like this

    array(
      'LocalClocks' => array(
        1 => 1,
        42 => 1
      )
    );
    

    And will omit any unchecked ones from the data array because we’re not using the hidden field. Finally, just a couple changes to your action

    public function deleteSelected()
    {
        foreach($this->request->data['LocalClocks'] as $key => $value)
        {
           $this->LocalClock->delete($key);
        }
        $this->redirect($this->referer());
    }
    

    I prefer using Model::delete() to Model::deleteAll() because it runs the callbacks, where deleteAll does not.

    Finally, your link will actually be a submit button. This will POST the data to the controller.

    echo $this->Form->end('Submit');
    

    If you want to use ajax, use the JsHelper to submit it instead. The following creates an Ajax submission that updates the dom element #mytable with the results of the action (in this case the referer that you redirect to).

    echo $this->Js->submit('Submit', array(
      'update' => '#mytable'
    ));
    echo $this->Form->end();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table column where each row has one of three states, and
I have 5 columns in a table. Column 1 has a check box named
I have a trigger to check for a single column in a table, when
I have table with date/time column and person column. Each person has multiple records
I have an HTML table in which the first column's cells each contain a
I have a table like this, and i have a checkbox at each row
I have a table with checkbox and text input column. The last row in
I have a table whose values are generated dynamically with PHP. Each row in
In this jsfiddle http://jsfiddle.net/littlesandra88/eGRRb/ have I submit buttons that are auto-generated. Each table row
I have a table of 50 odd rows with 11 columns. Each row has

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.