Symfony Form Standalone Save

Standalone Symfony Forms library wrapper

Project README

Symfony Form Standalone

This library allows to use symfony forms standalone without symfony framework and without pulling its dependencies.

Current dependencies list:

  • symfony/form
  • symfony/templating


composer require lostedboy/symfony-form-standalone

Basic Usage

Create form:

// index.php
use Symfony\Form\Standalone\FormBuilder;
use Symfony\Form\Standalone\Templating\FormTemplating;

// create form builder
$formBuilder = new FormBuilder();

// create form
$form = $formBuilder->create($formType, $mappedEntity);


// create templating handler
$formTemplating = new FormTemplating();

// get templating engine
$templating = $formTemplating->getTemplating();

// create form view
$formView = $form->createView();

// render form partial
echo $templating->render('form.html.php', array('form' => $formView));

Render form (see: Symfony Form Rendering)

// form.html.php 
<?php echo $view['form']->form($form) ?>

Render customization

// index.php
use Symfony\Form\Standalone\Templating\FormTemplating;

$formTemplating = new FormTemplating(
    // register directories with forms usages here
    // put form theme templates in some directory
    // register this directory in FormTemplating

Follow Symfony Guide


Any custom translator can be used. It should implement Symfony\Form\Standalone\Translation\TranslatorInterface

// index.php
use Symfony\Form\Standalone\Templating\FormTemplating;

$formTemplating = new FormTemplating([], [], new CustomFormTranslator());


Symfony Validator Component can be used

Install composer require symfony/validator Register validator extension:

// index.php
use Symfony\Form\Standalone\FormBuilder;
use Symfony\Component\Validator\Validation;

// create form builder
$formBuilder = new FormBuilder();

// configure validator
$validator = Validation::createValidatorBuilder()
        // paths to validation files (optional) 
        __DIR__ . '/config/validation/some_entity.yml'

// register extension
$formBuilder->addExtension(new ValidatorExtension($validator);


This bundle is under MIT license

Open Source Agenda is not affiliated with "Symfony Form Standalone" Project. README Source: lostedboy/symfony-form-standalone
Open Issues
Last Commit
3 years ago

Open Source Agenda Badge

Open Source Agenda Rating