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 8151753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:29:23+00:00 2026-06-06T15:29:23+00:00

I am trying to post an array of check box ids to an action

  • 0

I am trying to post an array of check box ids to an action in my controller. Here is the script from my index.ctp:

<script type="text/javascript">
$('.editSel_dialog').click(function()
{
    var selected = [];
    alert('Edit Selected Has Been Clicked');

    $("#[id*=LocalClocks]").each(function()
        {
        if(false != $(this).is(':checked'))
        {
            selected.push($(this).attr('id').replace('LocalClocks', ''));
        }
    });
    alert(selected);
    /*$.ajax(
    {
        type: 'POST',
        url: "/LocalClocks/editSelected/",
        data: selected,
        traditional: true,
        //contentType: "application/json",
        dataType: "text",
        success: function(data){ alert(data); alert('Edit Success');}
    });*/
    $.post('/LocalClocks/editSelected', { "Session" : selected }, function(data){
                   alert(data);
    });
});
</script>

I have both an ajax request and a post request. I was using the ajax until I saw that the post can actually modify a php variable. The code in the braces { "Session" : selected } should modify the Session variable with the array selected.

I tried using debug on $this->data, and $this->request->data, and $_POST, but they all are empty.

I need help getting the selected array written to a variable or something. I was thinking of trying to write to $this->Session but I am not sure how I would go about doing that.

Thanks in advance

  • 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-06T15:29:25+00:00Added an answer on June 6, 2026 at 3:29 pm

    With Cake, to get posted values in $this->request->data, their names have to be prefixed with data:

    Javascript:

    $.post('/LocalClocks/editSelected', { "data[Session][selected]" : selected }, function(data){
                   alert(data);
    });
    

    Controller:

    function editSelected()
    {
      if($this->request->is('post'))
      {
        if(isset($this->request->data['Session']['selected']))
        {
          $this->Session->write('selected', $this->request->data['Session']['selected']);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display some data from text file with an array. The
I am trying to get all checkboxes checked with: <script type=text/javascript> $(document).ready(function() { $(#delmsg_all).click(function()
I'm trying read an array that was post from a html form <input name=test[]
I'm trying POST a check-in request in Google Places API. The way they described
I'm trying to POST a http request using ajax, but getting a response from
I'm trying to post a JavaScript data object with the following: $.post(frm.attr(action), data, function(res)
Im am trying to add a check box that will enable/disable the edit button.
I'm trying to post some information from a from do so some calculations, however
I am going nuts here, I have an array of checkboxes from a form
Im trying to send a array to my method with $.post() but Im kinda

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.