1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| public function showAction(){
$formBuilderContact = $this->createFormBuilder()
->add('mail','email', array('attr'=> array('class' => 'form-control')))
->add('subject','text', array('attr'=> array('class' => 'form-control')))
->add('content','textarea', array('attr'=> array('class' => 'form-control')))
->add('recaptcha', 'ewz_recaptcha', array(
'constraints' => array(
new True()
)));
$formContact = $formBuilderContact->getForm();
$request = $this->get('request');
if ($request->getMethod() == 'POST') {
$formContact->handleRequest($request);
if ($formContact->isValid()) {
$mail = htmlentities($formContact->get('mail')->getData());
$subject = htmlentities($formContact->get('subject')->getData());
$content = htmlentities($formContact->get('content')->getData());
if($subject === null || $content === null || $mail === null || $subject == "" || $content == "" || $mail == "" ){
$this->get('session')->getFlashBag()->add(
'notification-danger',
'Veuillez indiquer votre adresse mail, un sujet et un contenu au formulaire de contact'
);
return $this->render('InAppsPassWayBundle:Contact:show.html.twig', array(
'formContact' => $formContact->createView()
));
}
//on vérifie aussi que l'adresse mail est une adresse valide
$emailConstraint = new EmailConstraint();
$errors = $this->get('validator')->validateValue(
$mail,
$emailConstraint
);//$errors vide si le mail est valide
if(count($errors) > 0){
//il y a des erreurs, l'adresse mail n'est pas valide
$this->get('session')->getFlashBag()->add(
'notification-danger',
'Veuillez indiquer une adresse email valide'
);
return $this->render('InAppsPassWayBundle:Contact:show.html.twig', array(
'formContact' => $formContact->createView()
));
}
//sinon on envoie le mail de contact
$message = \Swift_Message::newInstance()
->setSubject('Pass-Way, demande de contact')
->setFrom('no-reply@pass-way.net')
->setTo($this->_mailContact)
->setContentType('text/html')
->setBody($this->renderView('InAppsPassWayBundle:Contact:mail.html.twig', array(
'mail_expediteur' => $mail,
'content' => $content
)),
'text/html')
;
$this->get('mailer')->send($message);
//et on redirige vers la même page avec une notification
$this->get('session')->getFlashBag()->add(
'success',
'Votre demande de contact a bien été prise en compte, nous vous recontacterons le plus rapidement possible.'
);
return $this->redirect($this->generateUrl('in_apps_contact'));
}
}
return $this->render('InAppsPassWayBundle:Contact:show.html.twig', array(
'formContact' => $formContact->createView()
));
} |
Partager