Problem with Form Validation

In view file I have

<?php $form=$this->beginWidget('CActiveForm', array(



	));   ?>

<?php echo $form->textField($model,'fname', array("id"=>"txtSignUpName", "name"=>"txtSignUpName", "style"=>"border:1px solid #DCDCDD")); ?>

In model:

public function rules()


		return array(

			array('title, fname, lname, residence, contactType, contactNumber, gender, email, password, confrimpassword, admin', 'required'),




public function attributeLabels()


		return array(

			'fname' => 'First Name',


In controller:

public function actionRegistration()


		$model=new Userregistration('register');














if($model->validate()) is not returning true. why ?

When I submit the form after filling all the fields I get these errors on top

Please fix the following input errors:

Title cannot be blank.

First Name cannot be blank.

Last Name cannot be blank.

Residence cannot be blank.

Contact Type cannot be blank.

Contact Number cannot be blank.

Gender cannot be blank.

Email cannot be blank.

Password cannot be blank.

print_r($_POST); gives otuput

Array ( [ddltitle] => Capt. [txtSignUpName] => dasda [txtLastName] => dasda [ddlNationality] => Albania [ddlCountry] => Albania [ddlContactType] => Mobile [Country_Code] => 321 [Area_Code] => 321 [Contact_number] => 3231 [gender] => Male [txtSignUpEmail] => [txtSignUpConfirmPassword] => asdfg [Userregistration] => Array ( [confrimpassword] => asdfg [admin] => 0 ) [Register] => )

don’t change the name of the fields like “name”=>“txtSignUpName”. Remove the name from all fields. Yii knows the names already.

I changed the name and id because I have a javascript file pagescript.js for client side validation to check for empty fields and email pattern before form submission. I included that script file and changed the name and id of inputs corresponding to that in the script file but that validation is also not working

CActiveform has own client validation, just set ‘enableClientValidation’=>true.

Yii has everything you need to validate a form. Don’t change anything and you will see that it will work out of the box

just print the $_POST[‘Userregistration’] ,and exit; … u will get the answer.

see the printed values

the $_POST[Userregistration] only has these value [Userregistration] => Array ( [confrimpassword] => asdfg [admin] => 0 ) [Register] => )

got it?

<?php echo $form->textField($model,'fname', array("style"=>"border:1px solid #DCDCDD")); ?>

use like this

does ‘enableClientValidation’=>true runs validation on page reload ? I have included ‘enableClientValidation’=>true but the page reloads when I click on submit. I don’t want the page to reload

set enableAjaxValidation to true if you dont want the page to reload