Assign Values And Show Another In Yii Textfield


Here is what I face…

I need to add a readonly field in to a form and also a value which i pick from the same time i need to show a name in that text field and pass an integer to the DB as the value of that field.

<div class="row">

  <?php echo $form->labelEx($model,'pkg_id'); ?>

  <?php echo $form->textField($model,'pkg_id', array('readonly'=>true,'value'=>$pkg->pkg_id)); ?>

  <?php echo $form->error($model,'pkg_id'); ?>


in here as value i’m passing an id…but I need to show in the text field the name of that package…How can this be done???? :(

I think you need to change this




or whatever it is (based on your column name in db that have the ‘name of that package’ value). so it will show the name not the id.

yes it is…But then it will pass the name to the table…I need only to sen the id and show the name…anyway I handle it by adding a action in controller and get the id from model before save… :)

In view

<div class="row">

		<?php echo $form->labelEx($model,'pkg_id'); ?>

		<?php echo $form->textField($model,'pkg_id', array('size'=>10,'readonly'=>true, 'value'=>$pkg->pkg_name)); ?>

		<?php echo $form->error($model,'pkg_id'); ?>


In controller action



			$pkg_id = PortalPackages::model()->findByAttributes(array('pkg_name'=>$_POST['PortalUserProfile']['pkg_id']));




			$model->pkg_id = $pkg_id->pkg_id;





good then :)

May be you only need the following:

<div class="row">

  <?php echo $form->labelEx($model,'pkg_id'); ?>

  <?php echo $form->hiddenField($model, 'pkg_id'); ?>

  <?php echo CHtml::textField('pkg_id', $pkg->pkg_name, array('readonly' => true)); ?>