Zjoia
Zjoia

Reputation: 176

Symfony 1.4 Form Creater

Need: Ability to dynamically build Forms

Structure (simple idea not actual structure)

Admin: Form Assignment, where you create what field you want your new Form to have
FrontEnd: Where the New form will be implemented (this is the root of this question)
FronEnd Storage: When the New form is filled out the data points are written to a set of tables  

The idea is simple enough, Go into Admin, select the fields, fieldType, and Labels you want

I.E.

Field Name:*Enter a specific field name, like f_name or email  
FieldType: [Text, TextArea, Password, Radio, DatePicker, CheckBox, Select, etc]  
Label: What to display on the resulting form, f_name = First Name, etc  

Then I hit a page on the FrontEnd where the New form is generated, I fill it out and voila the data is stored in the FrontEnd Storage tables.

So the question is, idea's on how to accomplish this, I already have the Admin section done, it's dynamically building and appropriately binding a frontEnd From that I would like advice on.

Currently my idea is to simply make a shell form that is a huge ugly switch statement that builds sfForm elements and appropriate validators for each field (fields given from what was entered in the Admin area)

I feel this is the 'wrong' way to do it, I did find a plugin 'spyFormBuilderInterface2Plugin' which is old and build for propel not doctrine, but this is the basic idea of what I am after. So how would YOU do it?

Please note I am not looking to Dynamically ADD forms to a current form, I can already do this and it's exactly what is implemented in my Admin section, I need to take data a create a whole NEW form programatically

Upvotes: 1

Views: 342

Answers (1)

Grad van Horck
Grad van Horck

Reputation: 4506

I've created something like you described, just the way you said.

I have a model FormDefinition which defines a form, and has a collection of FormFields. Each form field has a widget_class, widget_options, validator_class and validator_options.

I have a custom myForm which needs a FormDefinition in it's constructor. In the setup() of myForm, I loop through all fields a instantiate the widgets and validators.

Beacuse in our solution, we needed/wanted to store all form data in separate tabels. My myForm extends from sfDoctrineForm, and my backend has some logic which creates/updates the (php) model and database definition, by just calling the appropriate Doctrine methods. But you could also create an EAV store.

Upvotes: 1

Related Questions