Exemplo n.º 1
0
 public function actionContact()
 {
     $model = new ContactForm();
     if (!Yii::$app->user->isGuest) {
         /** @var \gromver\platform\common\models\User $user */
         $user = Yii::$app->user->identity;
         $userParams = $user->getParamsArray();
         $model->name = $userParams['name'] ? $userParams['name'] : $user->username;
         $model->email = $user->email;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail(Yii::$app->grom->params['adminEmail'])) {
             Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Email is sent.'));
             return $this->render('contactSuccess');
         } else {
             throw new \HttpRuntimeException(Yii::t('gromver.platform', 'There was an error sending email.'));
         }
     }
     return $this->render('contact', ['model' => $model]);
 }
Exemplo n.º 2
0
 protected function launch()
 {
     $model = new ContactForm();
     if ($this->withCaptcha) {
         $model->scenario = 'withCaptcha';
     }
     if (!Yii::$app->user->isGuest) {
         /** @var \gromver\platform\common\models\User $user */
         $user = Yii::$app->user->identity;
         $userParams = $user->getParamsArray();
         $model->name = $userParams['name'] ? $userParams['name'] : $user->username;
         $model->email = $user->email;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->sendEmail(Yii::$app->grom->params['adminEmail'])) {
             Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Email is sent.'));
             return $this->render($this->successLayout);
         } else {
             Yii::$app->session->setFlash(Alert::TYPE_DANGER, Yii::t('gromver.platform', 'There was an error.'));
         }
     }
     echo $this->render($this->layout, ['model' => $model]);
 }