endroid/form-bundle

Endroid Form Bundle for Symfony

Installs: 1 260

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.1.0 2017-01-01 13:33 UTC

README

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License

The Endroid FormBundle enables users to create basic forms through the Sonata Admin Bundle. It includes form configuration, storage of results, sending of notifications when a form is filled in and even the possibility to export form results.

knpbundles.com

Requirements

  • Symfony

Installation

Use Composer to install the bundle.

$ composer require endroid/form-bundle

Then enable the bundle via the kernel.

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Endroid\FormBundle\EndroidFormBundle(),
    ];
}

Usage

Forms are created via Sonata Admin and can be rendered directly in your template as follows.

{{ render(controller('EndroidFormBundle:Form:show', { form: form })) }}

When a form is filled in correctly a result is generated and a form success event is dispatched. You can specify via Sonata Admin whether this result should be stored and if a confirmation email should be sent.

Extension

Event listeners

Event listeners exist for storing the result and sending a confirmation mail (depending on your settings). You can extend this functionality by adding your own listener or by overriding any of the existing.

/**
 * {@inheritdoc}
 */
public static function getSubscribedEvents()
{
    return [FormSuccessEvent::NAME => 'myHandler'];
}

/**
 * My custom form success handler.
 *
 * @param FormSuccessEvent $event
 */
public function myHandler(FormSuccessEvent $event)
{
    $result = $event->getResult();
    $form = $result->getForm();

    //...
}

And register it via the service container.

acme.event_listener.my_listener:
    class: Acme\EventListener\MyListener
    tags:
        - { name: kernel.event_subscriber }

Fields

New fields can be added by extending the Field class, creating a service definition for the the new field and adding the tag "endroid_form.field".

acme.field.my_field:
    class: Acme\Entity\MyField
    tags:
        - { name: endroid_form.field }

Versioning

Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.

License

This bundle is under the MIT license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.