diff --git a/form/form_collections.rst b/form/form_collections.rst index 00e524607fc..257b3605de7 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -251,23 +251,21 @@ The first thing you need to do is to let the form collection know that it will receive an unknown number of tags. So far you've added two tags and the form type expects to receive exactly two, otherwise an error will be thrown: ``This form should not contain extra fields``. To make this flexible, -add the ``allow_add`` option to your collection field:: +add the ``allow_add`` option to your collection field: - // src/Form/TaskType.php +```php +// src/Form/TaskType.php +public function buildForm(FormBuilderInterface $builder, array $options) +{ // ... - use Symfony\Component\Form\FormBuilderInterface; - - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder->add('description'); - - $builder->add('tags', CollectionType::class, [ - 'entry_type' => TagType::class, - 'entry_options' => ['label' => false], - 'allow_add' => true, - ]); - } + $builder->add('tags', CollectionType::class, [ + 'entry_type' => TagType::class, + 'entry_options' => ['label' => false], + 'allow_add' => true, + ]); +} +``` In addition to telling the field to accept any number of submitted objects, the ``allow_add`` also makes a *"prototype"* variable available to you. This "prototype"