Esempio n. 1
0
 public function actionContact()
 {
     $model = new ContactForm();
     if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
         Yii::$app->session->setFlash('contactFormSubmitted', 'Спасибо за обращение к нам. Мы ответим ближайшее время.');
         return $this->refresh();
     }
     return $this->render('contact', ['model' => $model]);
 }
Esempio n. 2
0
 public function actionContact()
 {
     $model = new ContactForm();
     if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->refresh();
     } else {
         return $this->render('contact', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * Contact
  */
 public function actionContact()
 {
     $model = new ContactForm();
     $toEmail = Yii::$app->params["adminEmail"];
     $model->load(Yii::$app->request->post(), "");
     if ($model->contact($toEmail)) {
         return ["success" => true];
     }
     return ["errors" => $model->errors];
 }
Esempio n. 4
0
 /**
  * Displays contact page.
  *
  * @return string|\yii\web\Response
  */
 public function actionContact()
 {
     $model = new ContactForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->contact(Yii::$app->params['adminEmail'])) {
             Yii::$app->session->setFlash('success', Yii::t('user', 'Thank you for contacting us. We will respond to you as soon as possible.'));
         } else {
             Yii::$app->session->setFlash('error', Yii::t('user', 'There was an error sending email.'));
         }
         return $this->refresh();
     }
     return $this->render('contact', ['model' => $model]);
 }
Esempio n. 5
0
 public function actionContact()
 {
     $model = new ContactForm();
     // ajax validation
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = 'json';
         return \yii\widgets\ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->refresh();
     } else {
         return $this->render('contact', ['model' => $model]);
     }
 }
Esempio n. 6
0
 public function testEmailIsSentOnContact()
 {
     /* @var ContactForm $model */
     $this->_model = $this->getMockBuilder('app\\models\\forms\\ContactForm')->setMethods(['validate'])->getMock();
     $this->_model->expects($this->once())->method('validate')->will($this->returnValue(true));
     $this->_model->attributes = ['name' => 'Tester', 'email' => '*****@*****.**', 'subject' => 'very important letter subject', 'body' => 'body of current message'];
     expect_that($this->_model->contact('*****@*****.**'));
     // using Yii2 module actions to check email was sent
     $this->tester->seeEmailIsSent();
     $emailMessage = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $emailMessage)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($emailMessage->getTo())->hasKey('*****@*****.**');
     expect($emailMessage->getFrom())->hasKey('*****@*****.**');
     expect($emailMessage->getSubject())->equals('very important letter subject');
     expect($emailMessage->toString())->contains('body of current message');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $class = ContactForm::find($id);
     if ($class->delete()) {
         return Response::json('success', 200);
     } else {
         return Response::json('error', 400);
     }
 }