A few helpers to make processing (creating, saving, errors, etc) forms simpler.

Installs: 271

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0


1.1.2 2017-10-24 19:46 UTC

This package is auto-updated.

Last update: 2023-03-15 11:00:23 UTC


A few helpers to make processing (creating, saving, errors, etc) forms simpler.


Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ php composer.phar require xm/form-bundle

This command requires Composer.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

// app/AppKernel.php

// ...
class AppKernel extends Kernel
    public function registerBundles()
        $bundles = array(
            // ...
            new XM\FormBundle\XMFormBundle(),

        // ...

Step 3: Add Service Alias

Adding the following will make the call to the service shorter:

form_handler: '@xm_form.handler'


Get the form handler

$formHandler = $this->get('form_handler');

Create the form

$form = $formHandler->getForm(

Process form & save entity

if ($formHandler->processForm($form, $entity, '[entity name]')) {
    // entity valid and saved successfully, redirect

Retrieve validation errors/messages as an array

This is useful when passing the validation messages to JS through JSON.

$errors = FormErrors::flatten($form)

This will return an array of the errors in the format of:

    0 => array(
        'Global Error 1',
    'field_name' => array(
        'Field Error 1',
        'Field Error 2',