Jump to content

Including changeable nested form depending on chosen field value and serialize


BagoZonde

Recommended Posts

Hello!

 

Is anybody know how to build Symfony 2 form (using Doctrine 2 and annotations) described as:

 

1. I have KingEntity which contains "type", "settings" and "something_else" fields. "Settings" field will contain serialized data as it can differ depending on "type" selected.

2. When type==1 I want get child-form (or something like that) QueenOne. And when type==2, I want get child-form QueenTwo, and so on. Each Queen* form contains different fields that's why I want to serialize it and put in "settings" field. I don't want to create new tables in database and create relations between them at all.

3. So, if type==1 is selected, I want validate this form using QueenOne form. If validation success, I want to serialize that data from QueenOne and put into "settings" field of KingEntity, so KingEntity is keeped in database and it contains only "type", "settings" and "something_else" fields.

4. I'm not interested with viewing this form, I need only backend part of logic for this kind of form.

 

I hope I've explained it clearly. Any help will be appreciated.

Ok, it was really easy thanks to validation_groups so all fields are available in one entity but splitted into groups. About serializing these fields to one "settings" field, I've used callbacks in that same entity like postLoad, prePersist and preUpdate. Case closed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.