I am trying to implement with custom function in model its not working i am not getting what's wrong in my code. i am trying to call with basic later i will put my condition.
Here is model code
public function rules()
{
return [
['mobile_number', 'required'],
['mobile_number', 'myfunction'],
];
}
public function myfunction($attribute,$params)
{
$this->addError($attribute, 'You have already submitted');
}
Here is controller code
public function actionCreate()
{
$model = new Createuser();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
its not assiging the error to a form-field.
Thanks in advance.
Code is fine. it was error with Dynamic Form validation.