form saves even though validation criteria are not met

Hi all,

I have a registration form with 4 fields, all required:

Email (unique)

Password (compare)

Password Repeat

Dropdown with indication of interest in products

When the user comes to the form, fills out an email and two matching password but does not chose any value things happen as they should:

No new record is created in the database and error message "cannot be blank" pops up.

Now when the user actually fills out the last field, the record gets created but it doesn’t redirect. Also, an error message appears saying that the email address is already taken. It’s as if the controller was trying to save the form twice.

Any help would be much appreciated.

Controller




	 /** Registering new user

	 * Creates a new model.

	 * If registration is successful, the browser will be redirected to the login page.

	 */

	public function actionRegister()

	{


                // create new instance of User

		$model=new User;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


                // for model validation rules

                // only 3 required fields for this scenario whereas update form has more required fields

                // see model User for more details

                $model->setScenario('register');




                if(isset($_POST['User']))

		{


                  


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


                     


                        if($model->save()) {

			                             

                           

                                

                              $this->redirect('index.php?r=site/login');


                        }

                        

		}


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

			'model'=>$model,

		));

	}



Model




public function rules()

	{

	

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		// different validations scenarios, see here http://php-thoughts.cubedwater.com/2009/validation-scenarios/

		return array(

			

			// scenario: register

			// password_repeat needs to be included for unknown reasons			

			array('email, password_repeat, password, tbl_user_interest_id', 'required', 'on'=>'register'),

			// compares password with password_repeat

			// for details check out Agile-Web-Application-Development-with-Yii11-and-PHP5-eBook09022011_1063898.pdf

			// only in this scenario because password field does not get displayed in scenario update

			array('password', 'compare', 'on'=>'register'),

                        array('email', 'unique', 'on'=>'register'),


                        [...]



Uncomment this line




// $this->performAjaxValidation($model);



/Tommy

Thx, solved.