0

I'm developing a Symfony Bundle for Polls. I tried to build my Poll with the Symfony Form builder but i had so many Problems due to my complex data, that i decided to build my Form manually in the html File.


Is there now any possibility to still do something like that:

if($form->isSubmitted() && $form->isValid())?


Do i have to send my form to another php-File like that: <form method="post" action="yourscript.php"> or can i still catch it in my Controller, which also had the action for opening the poll-file in it.


Or do i have to do it as it is described here?

I'm sorry for this noob question but when i search for form control with Symfony i only find stuff that explaines how to use the formbuilder.

7
  • yes, you can still use a Symfony controller. You would need to pull the form data from the Request object and then populate an Entity in order to persist to the DB. you cannot use and $form methods (validation, isSubmitted()) etc. Commented Dec 10, 2020 at 12:29
  • @craigh how do i pull the form data? like that: <form class="campaignForm" method="post" action="{{ path('path_to_the_method_that_processes_the_form_data')}}"> And how would i get the form data in this method then? Commented Dec 10, 2020 at 12:37
  • Agree with Craig, when you use a framework like Symfony (and not only some of its components) you should use it following the "Symfony way", but to use it correctly you need before to learn how to use its power, and for this there is a very large documentation to read (before use it) and you cannot avoid to do it :-) PS: I always found useful take a look at the source code to see how stuff works under the hood. Commented Dec 10, 2020 at 14:11
  • @Cerad my tip was in general and not strictly related to the form component. By the way I always prefer the old "simply is better if works" :-) Happy Coding! Commented Dec 10, 2020 at 15:49
  • @gp_sflover i did it for 2 months following the symfony way but then there was a Problem i struggled so hard, asked my colleagues for help, asked two questions on stack overflow, which both have no answer, and after trying and trying and always getting a new Problem when another one was solved we decided to do the form without the formbuilder. Commented Dec 11, 2020 at 15:30

1 Answer 1

2

You can do something simillar to Form with Request.

if ($request->isMethod(Request::POST)) { //check if method is post
  $request->request->get('yourFieldName'); //get values of  post data
}

I advice you to use Symfony Form instead of this !

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to get all of the Form data in an array so i can iterate through it? like $all = $request->request->get(all_form_data);
$request->request->all() EDIT:if it helps you do not forget to mark as resolved and vote for my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.