/** * * @Route("/feedback", name="feedback") */ public function feedbackAction(Request $request) { $feedback = new Feedback(); if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { $user = $this->getUser(); $feedback->setName(sprintf("%s %s", $user->getName(), $user->getSurname())); $feedback->setEmail($user->getEmail()); } $form = $this->createFormBuilder($feedback)->add('name', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('email', 'email', array('constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('subject', 'text', array('constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('message', 'textarea', array('constraints' => array(new NotBlank(), new Length(array('max' => 1000)))))->getForm(); //when the form is posted this method prefills entity with data from form $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); // save to db $em->persist($feedback); $em->flush(); return $this->userFeedbackSavedAction(); } return $this->render('common/feedback.html.twig', array('form' => $form->createView())); }