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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:43:01+00:00 2026-06-15T13:43:01+00:00

I had form content first name, last name …..etc. And tow drowpdownlist countries and

  • 0

I had form content first name, last name …..etc. And tow drowpdownlist countries and cities, I loaded cities when Country drowpdownlist changed by ajax, and everything is cool.
My problems:

1- when clicked submit and had error in validation, city value will replaced with empty value
How to fix it?

2- How to use $form-> with it I mean city drowpdownlist .

  • Form work if no error in validation
    Wrok

  • Form after clicked on submit and return error in validation like username is empty ..etc
    Error

View:

        <div class="row">
        <?php echo $form->labelEx($model,'البلد'); ?>
    <?php

    /*
     echo chtml::activeDropDownList($model,'country',$model->getcountry(),array('prompt'=>'اختر بلدك ')   , 
    array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('current/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city', //selector to update
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through
))

    ); 

    */
    echo CHtml::activedropDownList($model,'country',$model->getcountry(),

    array(
    'prompt'=>'اختر البلد أو المنطقة ',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('register/dynamiccities'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#city', //selector to update
//'data'=>'js:javascript statement' 
//leave out the data key to pass all form values through
))
    );

   ///

    ////

    ?>


        <?php echo $form->error($model,'country'); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model,'المدينة'); ?>
        <?php 

echo CHtml::dropDownList('city','', array());

 ?>
        <?php echo $form->error($model,'city'); ?>
    </div>

controller for cities load:

public function actionDynamiccities() /// Call Ajax
{
    $country=intval($_POST['Users']['country']);

    $data=Cities::model()->findAll('country_id=:country_id', 
                  array(':country_id'=>$country));
    $data=CHtml::listData($data,'id','city_name_e');
     echo CHtml::tag('option',
                array('value'=>''),CHtml::encode('Select Your City '),true);

    foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
                   array('value'=>$value),CHtml::encode($name),true);
    };
}
  • 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-15T13:43:03+00:00Added an answer on June 15, 2026 at 1:43 pm

    If you look at this line

    echo CHtml::dropDownList(‘city’,”, array());

    It is obvious that the list is empty, and it would also be empty if you wanted to edit the content later.

    I would suggest using something like

    echo CHtml::dropDownList(‘city’, $model->city, empty($model->country) ? array() : CHtml::listData(Cities::model()->findAllByAttributes(array(‘country_id’ => $model->country)),’id’,’city_name_e’));

    Here i don’t know if you should use $model->country or $model->country_id, depends on your model.

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

Sidebar

Related Questions

I had my code working earlier today, with first asks for your name with
I had another form to upload the details of 1 product which have multiple
I had written an event handler for MouseMove for my form but When I
i had sideshow ajax and i want it get images form database i used
I had developed one website purely in HTML .I have my form with fields
I just had an interesting experience with a startup form in MS Access 2010.
I've had troubles for a few days already with handling form that contains dropdown
Spreadsheet based Apps that were published as services had URLs of this form: https:
I have a form with 3 text fields and 3 checkboxes. I had implemented
I really like Play 2.0's form mapping system, but I had a question about

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.