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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:49:04+00:00 2026-05-24T13:49:04+00:00

I have a case where user can select multiple values in the list box

  • 0

I have a case where user can select multiple values in the list box and save it to the database using model.

Here is the table structure

user_id int(11) , cars_id int(5)

Here is the snippet of my view

<?php echo CHtml::dropDownList("sourceCars", '',CHtml::listData(MasterCars::model()->findAll(),'cars_code','car_name'),array('size'=>20) );?>

<?php echo CHtml::dropDownList("targetCars", '', array(),array('size'=>20) );?>

User selects the cars from sourceCars and moves into targetCars using Jquery ( This part is done) and
clicks on Save or Submit button .

Now I should be able to save all the cars he/she selected in the targetCars list. Moreover in model I should put a condition that user can’t save more than 10 cars and at least one car should be selected . Also user can select 5 cars at one time and next time when he comes he should be able to select max 5 cars only since he already save 10 records .

Could you please throw me some idea to implement this ? any Links that can guide me ?

  • 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-05-24T13:49:05+00:00Added an answer on May 24, 2026 at 1:49 pm

    your question is to limit selection of cars between 1-10.
    You need validate user input both client and server.
    At server,you can custom a ActiveRecord validation

    public function rules()
    {
        return array(
            array('cards_id', 'limitSelect','min'=>1,'max'=>10),
        );
    }
    
    public function limitSelect($attribute,$params)
    {
             //and here your code to get the count of selection of cars for a user
             ...
            if($count<=$params['min'])
               $this->addError('cards_id','at least one car should be selected');
            if($count>=$params['max'])
                $this->addError('cards_id',' can't select more than 10 cars');
    }
    
    
    
        //and for mutiple select you can code this:
    echo CHtml::dropDownList("sourceCars", '',CHtml::listData(MasterCars::model()->findAll(),'cars_code','car_name'),array('size'=>20,'multiple'=>true) );
    //anyway you can implement it in several way
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a payment page where the user can select from a list
I have to make a string by using the values which the user selects
I have a case that keeps coming up where I'm using a ListView or
I have a case where I need to translate (lookup) several values from the
I am trying to understand if I really have any case for using git/mercurial.
Have a use case wherein need to maintain a connection open to a database
I'm using a SELECT statement in T-SQL on a table similar to this: SELECT
I have a database table structured like this (irrelevant fields omitted for brevity): rankings
I have a UIPicker with 3 components containing numeric values, this allows the user
We have an stored procedure that we created so that user can write comma

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.