Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/contact", name="_demo_contact")
- * @Template()
- */
- public function contactAction(Request $request)
- {
- $contact = new Contact();
- // Set a default for message inside the data object itself.
- // I expect that if message is missing in the request, this value will be used as the default
- $contact->setMessage("Default message from controller");
- // Create the form with $contact as the initial data. Disable csrf to make the test more straightforward.
- $form = $this->createForm(new ContactType(), $contact, ['csrf_protection' => false]);
- $form->handleRequest($request);
- if ($form->isValid()) {
- return new Response("Good!", 200);
- } else if ($form->isSubmitted()) {
- // $message always returns a validation error even though I've set it on the underlying data object
- return new Response((string)$form->getErrors(true), 400);
- }
- return array('form' => $form->createView());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement