public function actionRegistration()
{
$model=new Userregistration();
if(isset($_POST['ajax']) && $_POST['ajax']==='userregistration-registration-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['Userregistration']))
{
$model->attributes=$_POST['Userregistration'];
print_r($_POST);
if($model->validate())
{
$model->save();
$this->actionIndex();
}
}
$this->render('registration',array('model'=>$model);
}
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'userregistration-registration-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
)); ?>
public function rules()
{
return array(
array('title, fname, lname, residence, contactType, contactNumber, gender, email, password, confrimpassword, admin', 'required'),
array('email', 'length', 'max'=>512),
array('email','email'),
array('email','unique'),
................................
array('id, title, fname, lname, nationality, residence, contactType, contactNumber, gender, email, password, confrimpassword, admin', 'safe', 'on'=>'search'),
);
}
Ajax validation is also not working when I focus out of empty field.
When I enter an invalid email format the email field box turns red. It doesn’t show any message. And if I enter an existing email address it doesn’t give any error. Only when I click on form submit and the page reloads is when I get this error at the top of the form.
Please fix the following input errors:
Email "zdsa@ffo.com" has already been taken.
I have tried ‘clientOptions’=>array(‘validateOnSubmit’=>true), but the page still reloads