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.
Edited by BagoZonde
Link to comment
Share on other sites

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.

Edited by BagoZonde
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.