Answer the question
In order to leave comments, you need to log in
How to create a form from request data in symfony form component?
Reading the documentation on how to use the form component symfony.com/doc/current/components/form.html. I use exactly the component, i.e. outside the framework as standalone.
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
$formFactory = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->getFormFactory();
$form = $formFactory->createBuilder()
->add('email', EmailType::class)
->add('pass', PasswordType::class)
->getForm();
$request = Request::createFromGlobals();
$form->handleRequest($request);
$data = $form->getData();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question