1

When i select value from drop down list, and I submit form, i want my drop down list to have selected value, not to be on default value again. I try like this, but not working:

 <?php echo $form->dropDownList($model, 'code', $countriesIssuedList, array('name'=>'countriesIssued'), $select = array($_POST['countriesIssued']));?> 

Also i would like to add a first value to be default, not from db, i want to do it in the code like this, array('empty'=>'--Select country--') but not working.

Thanks

2 Answers 2

1

If you must change the name of your dropdownList you must manually set the value of code to $_POST['countriesIssued'] in your controller/view. As for the default, prompt is used to set this.

<?php if(!$model->code) $model->code=$_POST['countriesIssued'];?> <?php echo $form->dropDownList($model, 'code', $countriesIssuedList, array( 'name'=>'countriesIssued','prompt'=>'--Select country--' ));?> 
Sign up to request clarification or add additional context in comments.

Comments

1

The second parameter (currently 'code') must be a key in this array: $countriesIssuedList

See for example here.


"Also i would like to add a first value to be default" ... perhaps you can use array_merge()?

1 Comment

Sorry you mean something like this, $form->dropDownList($model, array('code'=>$countriesIssuedList), $countriesIssuedList, array('name'=>'countriesIssued'));, if so it's not working like this, everything works fine when i use CHtml, but with $form widget no. Thanks Ivo

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.