Is it possible to create and render and array of forms I know about collections but they don\'t really fit in my idea?
What I want is something like this
The action :
$forms = [];
foreach ($articles as $article) {
$forms[$article->getId()] = $this->get('form.factory')->createNamed(
'article_'.$article->getId(), // unique form name
ArticleType::class,
$article
);
$forms[$article->getId()]->handleRequest($request);
if ($forms[$article->getId()]->isValid()) {
// do what you want with $forms[$article->getId()]->getData()
// ...
}
}
And a better way to render :
return $this->render('some_view.html.twig', [
'forms' => array_map(function ($form) {
return $form->createView();
}, $forms),
]);