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
Actually, your action method is incorrect. When you call refresh(), you basically reload the page. If the model has not been updated in the database, you will see nothing special, and no errors since you reload a fresh model.
This code will display the error as usual in your view :
/**
* @return \yii\web\Response
*/
public function actionRegister()
{
// Register Model
$model = new RegisterForm();
if ($model->load(Yii::$app->request->post()))
{
$post = Yii::$app->request->post('RegisterForm');
if ($model->validate())
{
// whatever
}
// return $this->refresh(); // do not refresh but...
}
// ... render the view with the current model, who's errors attribute is filled
return $this->render('register', compact('model'));
}
NB : also, you don't have to call errors() in your view, the ActiveFormField rendering method takes care of it for you :
= $form->field($model, 'CompanyName')->textInput()->label('Company Name') ?>
is enough