I learn this beautiful framework and excuse me for my english but i’m a little french…
Well, the Ajax Validation seems to be not activate :
SubscriptionController.php
public function actionCreate()
{
$model=new Subscription;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Subscription']))
{
$model->attributes=$_POST['Subscription'];
$model->subcriptionstart=time();
$model->subcriptionend=Subscription::add_date($day=0,$mth=Yii::app()->params['subcriptionperiodtry'],$yr=0);
$model->amount=Yii::app()->params['subcriptionamounttry'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('users_id, subcriptionstart, subcriptionend, amount', 'required'),
array('users_id, subcriptionstart, subcriptionend', 'numerical', 'integerOnly'=>true),
array('amount', 'length', 'max'=>10),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, users_id, subcriptionstart, subcriptionend, amount', 'safe', 'on'=>'search'),
);
}
I suggest you use Firebug Console to verify there’s an ajax request submitted from the create form, e.g when you tab away from an empty required field.
Enable Yii file logging and add Yii::trace() calls, e.g. to the performAjaxValidation() method.
Active seems to be a counter of active ajax requests. 0 should be normal (I first saw the value 1 until I updated the DOM view).
(It’s possible to see attached events by right-clicking a field and inspect it.)
Are you saying valid fields turn greeen when you tab away from them or click somewhere else? So what exactly isn’t working? In the screen dump you attached in post #5 there is an error message displayed. I guess you submitted the form before it showed up.
When i clic on a box, ajax validation is enabled but not on submit…
But a have a second problem…now :
public function actionCreate()
{
$model=new Subscription;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Subscription']))
{
$model->attributes=$_POST['Subscription'];
$model->subcriptionstart=time();
$model->subcriptionend=Subscription::add_date($day=0,$mth=Yii::app()->params['subcriptionperiodtry'],$yr=0);
$model->amount=Yii::app()->params['subcriptionamounttry'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Without Ajax all the zone load with this code, but not with Ajax…
public function actionCreate()
{
$model=new Subscription;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Subscription']))
{
$model->attributes=$_POST['Subscription'];
$model->subcriptionstart=time();
$model->subcriptionend=Subscription::add_date($day=0,$mth=Yii::app()->params['subcriptionperiodtry'],$yr=0);
$model->amount=Yii::app()->params['subcriptionamounttry'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
When i create a record, the validation work and with ajax :
PS : I need to add “clientOptions’=>array(‘validateOnSubmit’=>true)” if i want ajax to work.
each zone of the model is never updated
public function actionCreate()
{
$model=new Subscription;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Subscription']))
{
$model->attributes=$_POST['Subscription'];
$model->subcriptionstart=time();
$model->subcriptionend=Subscription::add_date($day=0,$mth=Yii::app()->params['subcriptionperiodtry'],$yr=0);
$model->amount=Yii::app()->params['subcriptionamounttry'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}