Ive two dropdown lists one for country and other for cities on my page. When i load the page initially i set the country to the default country loaded from the user registeration. Then i load the cities for that country.
The problem is that now when i change the country dropdown and refresh the page my country dropdown selected value remains the same which has changed but the cities are loading from the default country.
I'm getting the right value at the view from the controller but view is not setting it right. The code in my view is as follows
echo $this->Form->input('from_country_code',
array(
'options'=>$countries,
'id'=>'from_country_code',
'label' => __('Country',true),
'selected'=>$selectedCountryCode
)
);
Secondly, please explain me that how can i detect that a page is refreshed and retain the changed drop down values and don't execute the whole action controller code.
Any help would be highly appreciated.
Updated -- Here its my controller code
function add() {
$currentUser = $this->Auth->user();
$countryMap = $this->requestAction('/countries/getList/');
$this->set('countries',$countryMap);
$this->set('selectedCountryCode',$currentUser['City']['countriesCode']);
$cityMap = $this->requestAction('/cities/getListByCountryCode/'.$currentUser['City']['countriesCode']);
$this->set('cities',$cityMap);
if(!empty($this->data)) {
if($this->Request->saveAll($this->data)) {
$this->Session->setFlash('The Request was successfully Posted');
$this->redirect(array('controller'=>'users','action'=>'requests'));
} else {
$this->Session->setFlash('The Request was not saved. Please try again');
}
}
}
Please note that the issue i'm having is that on page refresh the selected property of the country dropdown is not setting properly. Ive checked the value from controller its coming correctly even if i refresh the page.
Im setting the selected country value in this variable @selectedCountryCode.