I Posted one question yesterday regarding custom validation for radio button Textfield Mandatory On Radio Button. I got answer. But, that was not exact answer. But, it solve
You should to add 'enableAjaxValidation' => true
in ActiveForm
.
After do this your code should be,
controller
public function actionRegister()
{
$model = new RegisterForm();
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()))
{
}
else
{
// HERE YOU CAN PRINT THE ERRORS OF MODEL
echo "";
print_r($model->getErrors());
echo "
";
}
return $this->refresh();
}
View
'register-form',
'enableAjaxValidation' => true,
]); ?>
.
.
.
= $form->field($model, 'AdminType')
->radioList(array('Individual'=>'An Individual', 'Firm'=>'Firm/Company'))
->label('Are You')?>
= $form->field($model, 'CompanyName')->textInput()->label('Company Name')->error() ?>
.
.
It may help you.