I have a Symfony form that is created from createFormBuilder() in the controller. But under two IF statements the form should carry two different set of fields. My Symfony versi
Try:
$formbuilder = $this->createFormBuilder()
->add('name', TextType::class, ['required' => true]])
->add('email', EmailType::class, ['equired' => true]]);
if($a==true){
$formbuilder->add('username', TextType::class, ['required' => true]])
->add('password', PasswordType::class, ['required' => true]]);
}
$form = $formbuilder->getForm();
if ($form->isSubmitted() && $form->isValid()) {
...
...
...
}