Scenario and validation problem with a very basic Form widget, help

I have a form with only one input field, I defined a validation on this field as ‘required’ and ‘email’, but when I click on submit, The form return with an empty input text with the message “Email cannot be blank”, I don;t understand, as I entered a valid email in it.

that are my rules in my model,


return array(

			array('contactID', 'required', 'on'=>'update'),

			array('contactID, order', 'numerical', 'integerOnly'=>true,'on'=>'update , create'),

			array('email', 'length', 'max'=>160,'on'=>'test'),

			array('email', 'required', 'on'=>'test'),

			array('email', 'email', 'on'=>'test','message'=>'must be an email, dude'),


			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, contactID, email, order', 'safe', 'on'=>'search'),

		);

and here is the action calling the preregister view in the controller :


public function actionPreregister(){

		$model = new BranchContactEmails('test');//her I put the scenario name defined in my rule set


		if(isset($_POST['BranchContactEmails'])){

			//search existing here

			var_dump($_POST['BranchContactEmails']);// I have my email displayed correctly


			if($model->validate()){

                              // THIS LINE never happen, but it should! 


			}

			else{

                               // if I don;t put this line, the input text appear empty

				$model->email=$_POST['BranchContactEmails']['email'];

			}

		}

		$this->render('preregister',array(

			'model'=>$model));

	}

I have a view file called preregister.php , I am a bit lost on this one, and new to Yii, I really love this framework BTW, and have decided that I 'll work on it for a while.

I just found the mistake I did, here the solution for others if needed :




public function actionPreregister(){

		$model = new BranchContactEmails('test');


		if(isset($_POST['BranchContactEmails'])){

			

                        //!!!HERE

                        $model->attributes=$_POST['BranchContactEmails'];

			

                        if($model->validate()){

				$this->redirect(array('to the next step, Yii rocks'));

			}

		}

		$this->render('preregister',array(

			'model'=>$model));

	}