Yii Framework Forum: Yii Dropdownlist Value Not Being Posted Inside Model Array - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Dropdownlist Value Not Being Posted Inside Model Array Rate Topic: -----

#1 User is offline   marc_bcn 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 25-December 13

Posted 30 August 2014 - 05:48 AM

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
0

#2 User is offline   Yatin Mistry 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 93
  • Joined: 11-March 14
  • Location:Mumbai

Posted 30 August 2014 - 07:13 AM

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
Yii Posts

Yes it is 2.0.0.
0

#3 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 967
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 30 August 2014 - 09:21 AM

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')); 
?>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users