i've created a crud using gii
i add some check boxes in the form to control showing or hiding textfields
i want to implement this logic rule "when you check check box and textfield appears this textfield is required"
so i use beforeValidate() on my cmodel like the following
public function beforeValidate()
{
if ($this->recycle) {//this is the checkbox
$this->validatorList->add(Yii::createComponent(array(
'class' => 'CRequiredValidator',
'attributes' => array('recycle_options'),//this is the textbox
)));
}
return parent::beforeValidate();
}
in my controller created automatically using gii
public function actionCreate()
{
$model=new MembershipItemCycles;
// Uncomment the following line if AJAX validation is needed
//$this->performAjaxValidation($model);
if(isset($_POST['MembershipItemCycles']))
{
$model->attributes=$_POST['MembershipItemCycles'];
if($model->save())
$this->redirect(array('view','id'=>$model->cycle_id));
}
$this->render('create',array(
'model'=>$model,
));
}
i tested that with an empty textfield with checkbox checked but nothing occurs and no errors and fields saved to my database
what error i've done ?

Help












