How To Automatically Update Textfield In Form

i have a form which works fine. i want to automatically update the form textfields with the variable information if defined else it will take user information.

suppose i have a form which takes name as input and i want to update it with yii::app->user->username or Yii::app()->user->email

then can anyone please help me how to do it. in case the value is not provided then user information should be taken.

thanks in advance.

I do something similar for my site’s “contact us” form.

When a logged in member pulls up the form I want to prepopulate their information since we already have them from the login process.

Just set the form’s attributes in the controller like this:




$model = new ContactForm;

$model->lastName = Yii::app()->user->firstName //or whatever

$model->email = ... //and so on



If you don’t have attributes available through Yii::app()->user you may just need to lookup the user by ID first:


$user=User::model()->findByPk(Yii::app()->user->id);