16

I'm trying to implement Symfony2 form builder component as a standalone. The documentation doesn't really talk about this though, just in relation to using the whole framework.

The standalone is on Github but has no docs.

Ive searched around and seen a few people ask this question but none seems to have any answers.

All I need is a basic guide on how to setup a form , build it, then view it.

Anyone?

j0k
  • 22,600
  • 28
  • 79
  • 90
BobFlemming
  • 2,040
  • 11
  • 43
  • 59
  • You might want to have a look at PEAR's [HTML_QuickForm2](http://pear.php.net/package/HTML_QuickForm2) which was build to be used standalone :) – cweiske Jun 07 '11 at 10:12
  • Thanks, I'm aware of other options for creating OO forms, I'm just interested in Symfony at the moment though. – BobFlemming Jun 08 '11 at 10:54

5 Answers5

11

Edit: My first response below is now obsolete (and the link does not work anymore). Please refer to https://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

Nicolas Clavaud
  • 156
  • 1
  • 5
3

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?).

Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
  • The Form component doesn't have the documentation as you are mentioning. We can add the class loader and stuffs . But still where the instantiation and where to do is not in docs. The docs mentions using it in Symfony controller . – Hari K T Dec 02 '11 at 08:28
2

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.

Nikola Petkanski
  • 4,724
  • 1
  • 33
  • 41
0

First of all not with Symfony2. But creating form with Aura.Input and some view helpers of Aura.View makes it easy to bring Standalone Forms and Validation.

If you are interested you can read it over http://harikt.com/phpform/ , and source is in github.

Hari K T
  • 4,174
  • 3
  • 32
  • 51
-2

/* * This file is part of the Symfony package.....

what i understand from that line is that the file is a PART of the framework, can't be removed, can't be ripped, and it won't function if you rip it off the package because it requires other related files in the framework

however, there is an option, and it is to investigate the files and see what functions they call and what variables they use ,redefine them, and use it as standalone IF the license allows you to

SAFAD
  • 774
  • 3
  • 14
  • 37
  • 2
    I think it can be "ripped off" from Syymfony2 as it was designed to be modular (PHP >=5.3 namespaces). You can for sure use [EventDspatcher](https://github.com/symfony/symfony/tree/master/src/Symfony/Component/EventDispatcher) component assuming you preserve directory structure and use some autoloader to include it, so I suspect Form Component is no different from that. – Grzegorz Rożniecki Jun 06 '11 at 20:06
  • yes i said that there is an option and is to rip off all the needed components with it too – SAFAD Jun 06 '11 at 20:18
  • [In docs there is something about components](http://symfony.com/components): _they can also be used standalone even if you don't use the framework as **they don't have any mandatory dependencies**_ – Grzegorz Rożniecki Jun 06 '11 at 20:32
  • then he probably needs to include form.php file and hes ready to go – SAFAD Jun 06 '11 at 20:48
  • Thanks. The documentation - as you've noticed - talks about the modular nature of Symfony2 components. From my brief experiments though, it seems that the Form component requires quite a few other components to work correctly , and which components these are is not documented. – BobFlemming Jun 08 '11 at 11:01