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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:13:17+00:00 2026-06-17T08:13:17+00:00

When adding a record, I let user mark as many checkboxes and needed: echo

  • 0

When adding a record, I let user mark as many checkboxes and needed:

echo $this->Form->input('us_roles', array('label' => 'Roles:',  'type'=> 'select', 'multiple'=>'checkbox','options' => $arr_pr_role));

and store selected indexes to a string field on my bd without a problem. (it saves eg. 1,2,3)

However, when editing that record, the checkboxes are not populated -selected- accodingly. (based on the string text, for example, 1,2,3

How can I have my checkboxex reflect the values stored as a string on the db?

My edit view uses the same as my add view:

echo $this->Form->input('us_roles', array('label' => 'Roles:',  'type'=> 'select', 'multiple'=>'checkbox','options' => $arr_pr_role));

** More detail

When adding a new record, I implode the selections from the select into my data:

$this->request->data['User']['us_roles'] = implode(",", $this->request->data['User']['us_roles']);

Same thing when saving an edited record.

The issue isUpon retrieval, how can I translate the string into my us_roles input?

echo $this->Form->input('us_roles', array('label' => 'Roles:',  'type'=> 'select', 'multiple'=>'checkbox','options' => $arr_pr_role));

Can you help?

— update, fixed—

    public function edit($id = null) {
    $this->User->id = $id;
    if (!$this->User->exists()) {
        throw new NotFoundException(__('Invalid user'));
    }
    if ($this->request->is('post') || $this->request->is('put')) {
        $this->request->data['User']['us_roles'] = implode(",", $this->request->data['User']['us_roles']);
        if ($this->User->save($this->request->data)) {
...
 } else {
             $this->request->data = $this->User->read(null, $id);
        $this->request->data['User']['us_roles'] = explode(",", $this->request->data['User']['us_roles']);

 }  
  • 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-17T08:13:18+00:00Added an answer on June 17, 2026 at 8:13 am

    Now I understand…
    You are looking for the opposite of implode().
    That would be explode().

    Or you can use the string class ( http://book.cakephp.org/2.0/en/core-utility-libraries/string.html#String::tokenize ):

    $array = String::tokenize($string, ',');
    

    should get you your array of values back.

    But believe me, there are usually better ways of doing that.
    You could make it another db table + model. You could use the ArrayDatasource, you could use some bitmasked solution like I do in such a case ( http://www.dereuromark.de/2012/02/26/bitmasked-using-bitmasks-in-cakephp/ ).
    The advantage of the last approach is that you still use only a single field (and very small amount of space) while you have the full capabilities of an extra table: Full search on NOT, AND, OR, …

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

Sidebar

Related Questions

i have one php file which process adding of record in Database fro array.
when adding a new record like this ContentContacts c2 = new ContentContacts(); c2.updated_user =
Related to this question , how do I detect that a form user is
I have seen various answers around helping explain adding records in one-to-many relationships but
Say, you are submitting a form, which affects your database (adding records/ deleting them/
Some social games on Facebook let user publish a link to their feed to
What I would like to do is record a voice, process it like adding
Let me illustrate this question with code first: with Ada.Text_IO; procedure Test is task
What I'm trying to do: To let the user be able to store data
I'm adding a record to a table using the following code: Dim rs1 As

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.