Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 dynamic form generation

I have mysql 2 tables: user_profile_field and user_profile_data with following columns:

user_profile_field:

-id (integer)
-field (string)
-category(string) 

user_profile_data:

-id (integer)
-user_id (integer)
-field_id (integer) references user_profile_field(id)
-data (string)

I also have defined 2 Doctrine entities that map this relation. I need dynamicaly to create a form for updating user_profile_data. The form input type for each row of user_profile_field depends on user_profile_field:category column (3 possible values correspond to different input types: text, textarea and choice field) ...

Im not sure how to create the form and form type entity via 'Symfony2' way ?

Any help or suggestion appreciated ...

like image 497
StPiere Avatar asked Feb 15 '26 16:02

StPiere


1 Answers

The Symfony 2 user documentation suggests the use of form events to generate a dynamic form: http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html

like image 157
Iain Avatar answered Feb 19 '26 11:02

Iain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!