Question

This is the same question asked here: Symfony2 standalone form component - setting up a form. The answer to this question seems to fully address the issue.

Unfortunately back when this question was asked the version of the form component was 2.0.x, and several things have changed since, for example the form creation using the form factory is quite different now compare the old code vs the new one.

I looked around but didn't find any documentation or examples on how to do this with the latest versions.

any updated versions of a sample application using the form component outside of Symfony2?

Was it helpful?

Solution

I have a repository demonstrating the standalone usage of the Form component for Symfony 2.1+ with both Twig and PHP as templating engine (check the branches): https://github.com/bschussek/standalone-forms/blob/2.1%2Btwig/src/setup.php

The crucial part is that you shouldn't instantiate FormFactory objects manually anymore (to give us core developers more flexibility in changing its constructor), but use the Forms class instead:

$formFactory = Forms::createFormFactoryBuilder()
    ->addExtension(new CsrfExtension($csrfProvider))
    ->addExtension(new ValidatorExtension($validator))
    ->getFormFactory();

A nice side benefit is that your IDE will list you the setters of the form factory builder, showing you what you can configure and how.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top