Пример #1
0
 /**
  * Creates a new ContactRequest model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ContactRequest();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 public function actionContact()
 {
     $model = new ContactRequest();
     if ($model->load(Yii::$app->request->post())) {
         $model->email = $model->email ? $model->email : Yii::$app->params['adminEmail'];
         $model->name = $model->name ? $model->name : 'Форма заказа';
         $model->duedate = Yii::$app->formatter->asDatetime($_POST['ContactRequest']['duedate'], 'Y-M-d H:i:s');
         if ($_POST['ContactRequest']['sizes']) {
             $model->sizes = join('; ', $_POST['ContactRequest']['sizes']);
             $model->sizes .= '; ' . $_POST['ContactRequest']['sizesmore'];
         }
         if ($model->save()) {
             $model->attachments = UploadedFile::getInstances($model, 'attachments');
             if ($model->upload()) {
             }
             $subject = 'Новый заказ от ' . $model->name . '<' . $model->email . '>';
             $body = 'Поступила новый заказ от ' . $model->name . '<' . $model->email . '>';
             $body .= '' . $model->initiator . "\n";
             $body .= '' . $model->task_type . "\n";
             $body .= '' . $model->description . "\n";
             $body .= '' . $model->slogan . "\n";
             $body .= '' . $model->sizes . "\n";
             $body .= '' . $model->duedate . "\n";
             $body .= '' . $model->proofs . "\n";
             $body .= 'Смотреть по ссылке ' . Url::to(['requests/view', 'id' => $model->id], true);
             $ses = Yii::$app->mailer->compose()->setTo(Yii::$app->params['adminEmail'])->setFrom([$model->email => $model->name])->setSubject($subject)->setTextBody($body)->send();
             if (!$ses) {
                 Yii::$app->session->setFlash('error', 'There was an error sending email.');
             }
             //create attachments
             Yii::$app->session->setFlash('contactFormSubmitted');
             return $this->refresh();
         }
     }
     return $this->render('contact', ['model' => $model]);
 }