2

I'm currently creating a form, something along the lines of:

$myDto = // ... etc - I am not using Doctrine

$form = $this->createForm(new DtoType(), $myDto);
$form->bind($request);

The values get bound to the form and end up assigned to $myDto. That's fine.

I would like to prepend a couple of extra fields to my form for a different object.

I could create a "composite" type which contains them both - I could call it CompositeFormType which contains DtoType (the original form) and ActionsType (the new fields), a bit like described here http://symfony.com/doc/current/book/forms.html#embedded-forms.

If that's the best way, then once I have created this CompositeFormType, how would I get the values in/out of the form? What would I pass to 'createForm'? So for example:

$myDto =   // ... etc
$actions = // ... etc

$form = $this->createForm(new CompositeFormType(), ???);

                  //                     What here? ^
                  //
                  // I want both 'actions' and 'myDto' to be populated by
                  // the child types? How?

$form->bind($request);

... or should I be doing it a completely different way? Thanks in advance for your pointers.

1 Answer 1

1

You can create a new class which owns both objects as properties and pass instance of this class to this composite form.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.