D
D
d999992021-02-12 17:12:51
symfony
d99999, 2021-02-12 17:12:51

How to add default value to Symfony form in ->add('company') method?

company is the value of the linked table with the list entity which is rendered as a select. How to add a default value (placeholder)?

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('email', EmailType::class)
            ->add('company')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BoShurik, 2021-02-12
@d99999

https://symfony.com/doc/current/reference/forms/ty...

D
d99999, 2021-02-12
@d99999

You need to specify the current Entity and then placeholder
->add('company', EntityType::class, [
'class' => User::class,
'placeholder' => 'Company'
])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question