Lukas Hirt
Lukas Hirt

Reputation: 48

How to add if into form builder in Symfony

I need to add extra input into my contact form for specific localisation and I'm looking for a solution that could do something like this:

$form = $this->createFormBuilder()
    ->add(input)
    if ($locale == "locale") {
        ->add(extrainput)
    }
;

Insted of creating two form builders with if and else.

Upvotes: 1

Views: 768

Answers (1)

Skander Ben Khelil
Skander Ben Khelil

Reputation: 125

add all of them, then you can do that :

$form = $this->createFormBuilder()
    ->add('input')
    ->add('extrainput')
    ->getForm(); 
if($test) {
    $form->remove('extrainput');
} 

Upvotes: 5

Related Questions