예제 #1
0
 public function actionContact()
 {
     $this->layout = "main-web";
     $model = new \app\models\Contact();
     if (Yii::$app->request->post()) {
         $post = Yii::$app->request->post();
         if ($model->load($post) && $model->validate()) {
             if ($model->save()) {
                 Yii::$app->session->setFlash('success', 'El Contacto ha sido guardado.');
                 $model->refresh();
             } else {
                 Yii::$app->session->setFlash('error', 'Error al guardar el Contacto.');
             }
         }
     }
     return $this->render('contact', ['model' => $model]);
 }
예제 #2
0
 public function actionContact()
 {
     $user = User::findOne(Yii::$app->user->id);
     $contact = new \app\models\Contact();
     $model = new ContactForm();
     if ($model->email == null) {
         $model->email = $user->parent->identity;
     }
     if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
         Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
         $contact->user_id = $user->id;
         $contact->email = $model->email;
         $contact->subject = $model->subject;
         $contact->body = $model->body;
         $contact->date = date('Y-m-d h:i:s');
         $contact->status = 0;
         $contact->save();
         return $this->refresh();
     }
     return $this->render('contact', ['model' => $model, 'user' => $user]);
 }