Q:

Passing temporary data back to hidden field in Yii

I'm trying to pass a temporary data from my form to my model. My form has a hidden data in it, but it does not get any values from my model. 
My form is
<?php echo $form->hiddenField($model, 'fieldName'); ?>
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>

I threw in  the data for my hidden field using JQuery, and then I proceeed to validate my form.
public function rules() 
{
    return array(       
        array('name, email, subject, phone, body', 'required','message' => '{attribute} Required'),
        array('resume', 'file', 'types'=>'txt,pdf,doc,docx', 'maxSize'=>2097152, 'tooLarge'=>'File has to be smaller than 2MB','allowEmpty'=>false),
        array('email', 'email'),
    );
}

Whenever the validation hits an exception, it returns all of the $_POST data I inputted except the data I sent from the hidden form.
How do I get the $_POST so it gets back to the hidden form?

A:

First:
The attribute must be declared as public in the model.
public $fieldName;

Add in rules() of Model the field with a safe mode array('fieldName','safe') :
public function rules() 
{
    return array(       
        array('name, email, subject, phone, body', 'required','message' => '{attribute} Required'),
        array('resume', 'file', 'types'=>'txt,pdf,doc,docx', 'maxSize'=>2097152, 'tooLarge'=>'File has to be smaller than 2MB','allowEmpty'=>false),
        array('email', 'email'),
        array('fieldName','safe'), // Add the custom field to 'safe' mode.
    );
}

