/** * Validation method * * @param $type * * @return array * @throws \yii\web\BadRequestHttpException */ public function actionValidate($type) { $model = new Payment(['scenario' => $type]); // throw exception if scenario wrong if (!in_array($type, [Payment::SCENARIO_PHONE, Payment::SCENARIO_CARD])) { throw new BadRequestHttpException('Wrong type'); } if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; // validate model $errors = ActiveForm::validate($model); return ['valid' => empty($errors), 'code' => empty($errors) ? self::CODE_OK : self::CODE_VALIDATION_ERROR, 'description' => $errors]; } }