Exemple #1
0
 public function render($options)
 {
     $name = $this->getOption('name', $options, 'contact');
     $configuration = $this->configurationFactory->create($name);
     $template = $this->getOption('template', $options, $configuration->getFormTemplate());
     $form = $formFactory = $this->formFactory->create($configuration->getFormName());
     return $this->renderTemplate($template, array('form' => $form->createView(), 'name' => $name));
 }
Exemple #2
0
 public function send($name, ContactInterface $model)
 {
     $configuration = $this->configurationFactory->create($name);
     $text = $this->templating->render($configuration->getRecipientTemplate(), ['data' => $model]);
     $subject = $this->translator->trans($configuration->getSubject(), [], $configuration->getTranslationDomain());
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($configuration->getFrom())->setReplyTo($model->getEmail())->setTo($configuration->getRecipient())->setBody($text, 'text/html');
     $this->mailer->send($message);
     if ($configuration->isConfirmMail()) {
         $this->sendConfirmMail($configuration, $model);
     }
 }
Exemple #3
0
 /**
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function submitAction(Request $request)
 {
     $name = $request->get('name');
     $configuration = $this->configurationFactory->create($name);
     $form = $this->createForm($configuration->getFormName());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $model = $form->getData();
         $this->contactMailer->send($name, $model);
         $response = new JsonResponse(array('message' => $this->translator->trans('contact.form.message.success', [], 'EnhavoContactBundle')));
     } else {
         $errors = $this->formErrorResolver->getErrors($form);
         $response = new JsonResponse(array('message' => $errors[0]), 400);
     }
     return $response;
 }