tklustig
tklustig

Reputation: 503

Yii2.0/Rules for dropdownlist

I've following dropdownlist:

<?= $form->field($model, 'Urlaubsziel')->dropdownList([
    1 => 'USA', 
    2 => 'Mexico',
    3 => 'Deutschland', 
    4 => 'England',
    5 => 'Frankreich',],['prompt'=>'Select Country']);?>

How to define a rule to get content of choice in public function rules(){}? ['Urlaubsziel','string'] just will give me the number,not the content

Upvotes: 0

Views: 84

Answers (1)

Irfan Ali
Irfan Ali

Reputation: 2258

Update your code like below.

 <?= $form->field($model, 'Urlaubsziel')->dropdownList([
    'USA' => 'USA', 
    'Mexico' => 'Mexico',
    'Deutschland' => 'Deutschland', 
    'England' => 'England',
     'Frankreich' => 'Frankreich',],['prompt'=>'Select 
   Country']);?>

Upvotes: 1

Related Questions