Yii Dropdownlist Value Not Being Posted Inside Model Array

Hello all,

I’m having trouble creating a dropdownlist for a form model.

Specifically, the field of the dropdownlist is being posted outside the model array.

My model has 3 fields that have to be filled with the following form


<?php echo CHtml::beginForm($this->createUrl('prova/index'),'post', array('id'=>"create-shop-form") ); ?>                


	<?php echo CHtml::activeTextField($model,'name', array('class' => 'form-control')) ?>


	<?php echo CHtml::activeTextField($model,'scode', array('class' => 'form-control', 'placeholder'=>'url_de_la_botiga')) ?>

	

	<?php

		$options = array ('€' => '€');

		 echo CHtml::dropDownList('currency', $model, $options,  array('class' => 'form-control')); ?>

		 

	<button type="submit" class="btn btn-primary">Create</button>

<?php echo CHtml::endForm(); ?>

And this is what I receive in the controller. As you see, ‘currency’ is outside the array.


array (size=3)

  'YII_CSRF_TOKEN' => string 'f1b0dfe495558ede162157589409b8b1c536e6c1' (length=40)

  'Shop' => 

    array (size=2)

      'name' => string 'whatever' (length=0)

      'scode' => string 'whatever' (length=0)

  'currency' => string 'euro' (length=3)

Which way I have to follow to link this dropdownlist to the model?

Thanks

You dropdownlist should be like

Try this


$form->dropDownList($model,'currency',$options, array('class' => 'form-control'));

if not works then post you view source for your form

there is a method on CHtml activeDropDownList you could try that here is what it will look like


<?php

$options = array ('€' => '€');

echo CHtml::activeDropDownList($models, 'currency', $options,  array('class' => 'form-control')); 

?>