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.

lxg95
  • 553
  • 2
  • 8
  • 28
  • 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. – craigh Dec 10 '20 at 12:29
  • @craigh how do i pull the form data? like that: ```
    ``` And how would i get the form data in this method then?
    – lxg95 Dec 10 '20 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. – gp_sflover Dec 10 '20 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! – gp_sflover Dec 10 '20 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. – lxg95 Dec 11 '20 at 15:30
  • Mine was not a criticism but only a fact. Symfony is "the PHP framework" (component-based), with which you can build any type of project, BUT has an high learning curve and 2 months could be not enought to learn well all what it takes (and the Form component is certainly not the easiest one). It was built to not reinvent the well so my tip is to dedicate more time to learn how the Form component works. Maybe is a bit off-topic, but can I ask you why you need a bundle? Which version of symfony are you using? – gp_sflover Dec 11 '20 at 17:33
  • PS: try to take a look at [CraueFormFlowBundle](https://github.com/craue/CraueFormFlowBundle), maybe it could help you in some way with the use of the Form component. – gp_sflover Dec 11 '20 at 17:33

1 Answers1

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 !

  • 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);``` – lxg95 Dec 11 '20 at 15:33
  • `$request->request->all()` **EDIT**:if it helps you do not forget to mark as resolved and vote for my answer – Alexandre Painchaud Dec 11 '20 at 15:42