Using symfony 2.0.x form component standalone

368 Views Asked by At

How does one use the symfony-form component standalone for version 2.0.*? The examples in the documentation show how to create forms, but they use other parts of the symfony ecosystem, like controllers and actions that I currently do not know anything about, and I don't want to add those other components to my project.

I'm stuck using a system that has php 5.3.27, so I am unable to use a later version of symfony.

2

There are 2 best solutions below

0
KyoreG On BEST ANSWER

What I've done works so far, I just looked at the source code of the form component tests to figure out how forms were instantiated without the use of the symfony framework. Here is example code that worked for me:

use Symfony\Component\Form\Extension\Core\CoreExtension;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();

$coreExt = new CoreExtension();    
$formFactory = new FormFactory(array($coreExt));
$formBuilder = $formFactory->createBuilder('form');

$formBuilder->add('firstname', 'text');
$form = $formBuilder->getForm();
$form->bindRequest($request);
$formView = $form->createView();
2
sydney On

You are looking at the wrong documentation. If you want to use symfony2 forms as a stand alone component, you should look at the component documentation. http://symfony.com/doc/current/components/form/introduction.html

Use composer to determine the component version that matches your php version