Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Pull request Compare This branch is 72 commits behind simplethings:master.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status

This bundle contains additional functionality for Symfony2's Form Component.

Currently this Bundle provides the following:

  • RecaptchaFieldType for using Google's reCAPTCHA service.
  • ImageType for showing the previously uploaded image
  • FileSet for showing a list of previously uplaoded files
  • FieldTypeExtension for allowing setting attr when building a Form.

Current this Bundle does not provide the following:

  • In depth documentation.
  • Unicorns or other fairytale creatures.


Thanks to all who have helped make this bundle awesome. For a list of people who have helped you should visit this page:


If you want to help create a fork of this repository do some coding and send a Pull Request.


Fire up a terminal and either clone this repository or add it as a submodule both are shown here by example.

$ git clone git:// vendor/bundles/SimpleThings/FormExtraBundle
$ git submodule add git:// vendor/bundles/SimpleThings/FormExtraBundle

the enable to the bundle inside your kernel class normally called AppKernel.php


public function registerBundles()
    // ...
    new SimpleThings\FormExtraBundle\SimpleThingsFormExtraBundle(),
    // ...



// ...
$builder->add('recaptcha', 'formextra_recaptcha');
// ...
# app/config/config.yml
        private_key: "your-private-key"
        public_key:  "your-public-key"

When doing functional testing it is not possible to use the real Google Recaptcha API therefor there is a SimpleThings\FormExtraBundle\FunctionalTest\Recaptcha which always returns true.

It can be used by overwriting the DependencyInjection parameter in app/config/config_test.yml

    simple_things_form_extra.service.recaptcha.class: SimpleThings\FormExtraBundle\FunctionalTest\Recaptcha


Sometimes it is needed to show the value of a field without having it be an input box. This is where PlainType comes in handy. It will render a simple p tags with the fields value and also prevent that field from being bound if the form is tampered with.

// ...
$builder->add('username', 'formextra_plain');
// ...


FileSetType allows you to incrementally add more files to a collection of files by extending the FileType. It renders an unordered list of all the previously uploaded base filenames.

Instead of returning the previously added file you return an array of all file names from the fields getter method and in the setter method you append the newly uploaded file to the collection:

class Document
    // temporary field, used in the form, to move new attachments to persistence
    private $newAttachment;
    // persistent array with all attachments.
    private $attachments;

    public function getNewAttachment()
        $files = array();
        foreach ($this->attachments AS $attachment) {
            $files[] = $attachment->getFilename();
        return $files;

    public function setNewAttachment(File $newAttachment = null)
        $this->newAttachment = $newAttachment;

    public function moveNewAttachment()
        // code to move file and include in the attachments field.

Using the builder to create a field for this type would then look like:

$builder->add('newAttachment', 'formextra_fileset', array(
    'type' => 'file',

There are optional parameters 'delete_route' and 'delete_id' which are then used with twigs path method to generate a route with parameters "id" and "file", to delete the listed file. If the information passed is not enough you should overwrite the twig template with your own logic to implement deleting.


A Field Extension contains method called by FormBuilder or createView. These applies to all fields specified in the dic tag alias.

This example will preset the class attribute on the rendered textarea html element.

// ...
$builder->add('body', 'textarea', array(
    'attr' => array(
        'class' => 'niceditor',
// ...


Converts html code into entites. Also extends htmlentities function to auto guess the used charset if mbstring extension is availible.

// ...
$builder->get('body')->prependNormTransformer(new HtmlEntitiesTransformer(ENT_COMPAT, true));
// ...


Provides easy tag stripping capabilities for your forms to reduce xss attacks. You note it is not the best solution.

// ...
// This will allow <p> tags.
$builder->get('body')->prependNormTransformer(new StripTagsTransformer('<p>'));
// ...
Something went wrong with that request. Please try again.