adamquaile/symfony-fieldset-bundle

Fieldset Type in Symfony Forms

Installs: 41 005

Dependents: 0

Suggesters: 0

Security: 0

Stars: 17

Watchers: 3

Forks: 11

Open Issues: 8

Type:symfony-bundle

v1.1.3 2017-05-24 13:16 UTC

This package is auto-updated.

Last update: 2024-12-06 00:21:11 UTC


README

Adds a fieldset type to a symfony project.

Installation

Install via composer from adamquaile/symfony-fieldset-bundle.

Register in app/AppKernel.php:

public function registerBundles()
{
    $bundles = array(
        // ...
        new AdamQuaile\Bundle\FieldsetBundle\AdamQuaileFieldsetBundle(),
    );

    //...
}

Usage

Use with normal form builder methods:

// A fieldset with your fields defined in a callback function
$builder->add('my_group_example_one', FieldsetType::class, [
    'label' => false, // You probably don't want a label as well as a legend.
    'legend' => 'Your fieldset legend',
    'fields' => function(FormBuilderInterface $builder) {
        $builder->add('first_name', TextType::class, [
            'label' => 'First Name'
        ]);
        $builder->add('last_name', TextType::class, [
            'required'  => false,
            'label'     => 'Surname'
        ]);
    }
]);

// A fieldset with your fields defined in an array
$builder->add('my_group_example_two', FieldsetType::class, [
    'label' => false,
    'legend' => 'Your fieldset legend',
    'fields' => [
        [
            'name'  => 'first_name',
            'type'  => TextType::class,
            'attr'  => [
                'label' => 'First Name'
            ]
        ],
        [
            'name'  => 'last_name',
            'type'  => TextType::class,
            'attr'  => [
                'required'  => false,
                'label'     => 'Surname'
            ]
        ]
    ]
]);