public function actionIndex()
 {
     $model = new Subscriber();
     $request = Yii::$app->request;
     if ($model->load($request->post())) {
         if ($request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             $returnUrl = $model->save() ? $request->post('successUrl') : $request->post('errorUrl');
             return $this->redirect($returnUrl);
         }
     } else {
         return $this->redirect(Yii::$app->request->baseUrl);
     }
 }
Beispiel #2
0
 public function actionIndex()
 {
     $model = new Subscriber();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if ($model->save()) {
                 Yii::$app->session->setFlash(Subscriber::FLASH_KEY, 'success');
             } else {
                 Yii::$app->session->setFlash(Subscriber::FLASH_KEY, 'error');
             }
             return $this->redirect(Yii::$app->request->referrer);
         }
     } else {
         return $this->redirect(Yii::$app->request->baseUrl);
     }
 }