Symfony2 standalone form component - setting up a form Symfony2 standalone form component - setting up a form symfony symfony

Symfony2 standalone form component - setting up a form


Edit: My first response below is now obsolete (and the link does not work anymore). Please refer tohttps://github.com/webmozart/standalone-forms for a state-of-the-art solution.


Previous (now obsolete) answer:

I've tried hard and managed to display a form (using PHP engine, not Twig).

Indeed you need a few components: Form, but also ClassLoader, EventDispatcher, Templating (for rendering) and Translation (for rendering labels). You will also need some resources from the FrameworkBundle bundle (mainly templates).

More info on this:http://forum.symfony-project.org/viewtopic.php?f=23&t=36412

And my mini-tutorial:http://n.clavaud.free.fr/blog/index.php?article31/symfony2-standalone-form-component-tutorial


First, copy Form Component to your project to directory which contains third-party libraries (not only Symfony components, but also ORM or whatever), let's say lib/, so it's in <project_path>/lib/Symfony/Component/Forms.

Then you have to auoload it - either manually or using any PSR-0 compatible class loader i.e. SplClassLoader or Symfony's UniversalClassLoader (there is chapter in docs and in quick tour about this). Example:

$loader = new UniversalClassLoader();$loader->registerNamespace('Symfony', __DIR__.'/lib');$loader->register();

Using Form Component isn't in fact strongly documented, but in Symfony Book there are few examples how to use Form classes about this component, so I guess you'll have to dive into sources, beginning with Form class (maybe later you'll give some feedback about experiences somewhere in the Web?).


Since Symfony 2.1, the form component has been using composer.

You can locate the composer.json file inside the repository. It contains a dependency map that can be used to get the dependencies installed.

You can do so by simply running composer install from inside your console.

P.S I know this thread is old. The information I'm contributing apply to any new users that may need it.