[body listener] how are embedded forms (and collections) handled? #388

patkar opened this Issue Mar 6, 2013 · 3 comments


None yet
3 participants

patkar commented Mar 6, 2013

In one of my forms I'm using a collection of embedded forms

$builder->add('addresses', 'collection', array(
                    'type' => new AddressType(),
                    'allow_add' => true,
                    'allow_delete' => true,
                    'by_reference' => false,
                    'description' => 'Array of addresses',

How the json must look like, that the body listener recognizes the addresses array and I can bind the request correctly to my form?
This json would be logic to me, but it doesn't work.

    "user": {
        "username": "foo",
        "email": "foo@example.org",
        "plainPassword": "hahaha",
        "firstname": "Foo",
        "lastname": "bar",
        "language": "en",
        "addresses": [{
            "type": "invoice",
            "street1": "Broadway 1",
            "zip": "12345",
            "city": "New York",
            "country": "US"

My controller, which handles the post request is very basic.

 * @Rest\Post("/users")
 * @Rest\View
public function newAction()
    return $this->processForm(new User(), new RegistrationUserType());

private function processForm(User $user, FormTypeInterface $type)
    $userManager = $this->get('fos_user.user_manager');
    $statusCode = (null === $user->getId()) ? 201 : 204;

    $form = $this->createForm($type, $user);

    if ($form->isValid()) {
        $user = $form->getData();
        return $user;


        $response = new Response();
            ->set('Location', $this
               ->generateUrl('gps_api_user_get', array(
                       'id' => $user->getId()
               ), true));

        return $response;

    return $form;

borisguery commented Mar 14, 2013

it should work out of the box, I use such similar feature successfully. Maybe you should clarify what "doesn't work". However, your question would better fit on the mailing list, irc, or SO to avoid bloating the issues list :)


lsmith77 commented May 7, 2013


patkar commented May 8, 2013

close, 'cause not a bug or issue. Sorry for bloating the issue list.

patkar closed this May 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment