Thanks for the pointer. As a followup, I post my working solution
here:

This is what I do in my controller:

private function getSignupForm($customer) {
        $form = $this->get('form.factory')->create(new Form
\CustomerType(), $customer);
        // remove regular email field
        $form->remove('email');
        $userForm = $this->container->get('fos_user.form.user');
        $form->add($userForm);
        return $form;
    }

This is what I do in CustomerType::buildForm

$builder->addEventListener(Events::preBind, function (DataEvent
$event)  {
               $form = $event->getForm();
               $data = $event->getData();
               if(!empty($data['user'])) {
                    $customer = $form->getData();
                    $customer->setEmail($data['user']['email']);
               }
           });

It works, but I'm not sure if this is really recommended way to do
this.


On 27 Mai, 06:52, ericclemmons <ericclemm...@gmail.com> wrote:
> There is a similar discussion here:
>
> http://groups.google.com/group/symfony-users/browse_thread/thread/585...
>
> As for myself, I've been using an EventSubscriber and listing to the
> `postBind` event of one of the entities to gather the data and update
> the other form via a `bind` call.
>
> On May 26, 2:14 pm, thesaint <gabriel.bi...@gmail.com> wrote:
>
>
>
>
>
>
>
> > In my application I have users and every user has one or more customer
> > entities. Users and customers both have a mandatory email field. When
> > a new user signs up, I embed the customer form in the user form, but
> > only want to present one email field to the user. How can I send the
> > value from the field of one model to the other when the "bind" method
> > is invoked? Are there events I can use or should I rather override
> > some form method?

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to