I want to make successive form with Symfony 2.7 (2 forms) but I can not. The second form uses data from the first.
I tried this :
if($request->getMethod() === 'POST') {
$lot = new Lot();
if($request->request->has('logiciel_version_debut_form')) {
/*
SEND FIRST VALUE FORM
*/
$lot->setDateDebut(new \DateTime($request->get('logiciel_version_debut_form')['date_debut']['year'] . '-' . $request->get('logiciel_version_debut_form')['date_debut']['month'] . '-' . $request->get('logiciel_version_debut_form')['date_debut']['day']));
}
/*
SECOND FORM FORM
*/
$form = $this->createForm('logiciel_lot_form', $lot);
$this->submit($form);
if ($form->handleRequest($request)->isValid()) {
/*
OK GOOD :-)
*/
}
} else {
/*
FIRST FORM
*/
$form = $this->createForm('logiciel_version_debut_form');
$this->submit($form);
}
return array(
'form' => $form->createView(),
'title' => 'Ajouter un nouveau lot'
);
But it does not test if the first is valid. Can you help me ?
You can't doing what you want with autobinding handleRequest() in the same level request.
You can easily create a flow from FormType with this bundle: CraueFormFlowBundle