Answer the question
In order to leave comments, you need to log in
When not to use forms?
If you need to send one text field, well, or 2 - one text field, the second is a checkbox, let's say this is a search page
Does it make sense to create all this
$form = $formFactory->createBuilder()
->add('task', TextType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
$data = $form->getData();
// ... perform some action, such as saving the data to the database
$response = new RedirectResponse('/task/success');
$response->prepare($request);
return $response->send();
}
Answer the question
In order to leave comments, you need to log in
Well don't use Symfony Forms for your case if you don't want to. You can also get GET, POST parameters from superglobal arrays and not use the $request object, which already returns satinized data.
IMHO the question is in your regard. Today the form has 2 fields, and tomorrow you need 3 more, then 2 more, and that's it. You will have to refactor. I do not understand what the problem is to lay it right away?
As for me, the forms in the symphony are quite worthy.
And don't create the form on the fly in the controller - that's bad form. It is better to keep the forms in a separate class and give the processing to the manager when submitting. Thus, the controller will not twitch when increasing the functionality, and should not.
Yes, in your case you don't need to use the forms component at all. One of the tasks of a form is to map data into an object. As far as I understand, you do not need a mapping, which means that the form is not needed either. One example of when forms should not be used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question