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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:35:04+00:00 2026-06-03T23:35:04+00:00

I have two arrays. One is $categories which contains all categories retrieved from my

  • 0

I have two arrays. One is $categories which contains all categories retrieved from my db and the other is $preSelectedCategories which contains the categories that needs to be pre-selected in my check box list when my form is loaded. I tried to do this:

<?php echo $form->labelEx($model,'category_id'); ?>
<?php echo $form->checkBoxList($model, 'category_id', $categories, $preSelectedCategories, array('multiple'=>true)); ?>
<?php echo $form->error($model,'category_id'); ?>

But I did not succeed. Could anyone help me solve this problem? Thanks!

Edit: I already knew that using CHtml::checkBoxList could help, but what I want here is to use CActiveForm::checkBoxList because I am using a model to validate the checkbox list.

  • 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-03T23:35:05+00:00Added an answer on June 3, 2026 at 11:35 pm

    One option would be to use CHtml::activeName to get an appropriate name for the input and pass it to CHtml::checkBoxList, like others have suggested.

    Another option that is, in my opinion, more appropriate would be to add those category_ids you want pre-checked to the model in the controller, before rendering the form (only when it’s a GET request). Then you wouldn’t need to modify the form at all.

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

Sidebar

Related Questions

I have two arrays of data that I'm trying to amalgamate. One contains actual
I have two arrays. One for data and one which contains 1 for each
I have two arrays. One contains id=>count and the other contains id=>name . I'm
Say I have two arrays where one is a permutation of the other: A
I have two arrays, one is very large (more than million entries) and other
I have two arrays. I'd like to copy ranges of data from one of
I have two cell arrays one called info{} and the other is called data{}
I have two tabs one called Sale-Items and the other All-Items and for each
Let's say I have two arrays: one is the regex and the other one
I have two arrays, one is for a case and other one for b

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.