dropDownList Values and IDs

I am new to Yii and am having trouble wrapping my head around how the forms work. I am using a dropDownList like this:

<?= $form->field($model, 'type')->dropDownList(Type::find()->select(['type'])->indexBy('id')->column(), ['prompt'=>'Select Profile Type'])->label('Profile Type') ?>


        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => 'btn btn-primary']) ?>


My problem is that I want the form to post the ‘type’ attribute, but it only posts the ID. If I remove ->indexBy(‘id’), it always posts “0”. If I remove ->column() then the dropdown is populated with giberish. How can I get get the form to post the selected value? What if I wanted to return another column than the one selected in the dropdown? Is it possible to do that?

I’m not sure if this is a related question, but what are the variables in the models for? Are they supposed to capture the posted values? I can’t get them to work and they seem to be useless to me. If I leave them declared, they seem to mess up any posted values. Rather than using $type, I can just use $this->type. What are they for?

Thanks for any help!


link will helps You.

$items = ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name');



echo $form->field($model, 'name_field')->dropDownList(


        ['value' => selected value, 'class' => '']


Hello ,

If you want to post value of type field you should update like this:


The value return will :


'value_of_type" => "value_of_type"


To get other value:


The value you want to post will be here : [size=2]indexBy(‘type’)[/size]

Thank you. That did the trick. I thought I had tried indexBy(‘type’), but then again I have been trying a hundred different things, so I’m not sure.