0

I'm trying to insert a data passed in the form (e-mail) in the response that I create in the listener to ensure that the response is a json object.

I can not take the form data from 'event in any way ..

There is a solution to what I want?

public static function getSubscribedEvents()
{
    return array(
        FOSUserEvents::PROFILE_EDIT_SUCCESS => 'onProfileEditSuccess',
    );
}

public function onProfileEditSuccess(FormEvent $event)
{

    $response = new Response();
    $output = array('success' => true, 'new_mail' => $event); //event return empty object
    $response->headers->set('Content-Type', 'application/json');
    $response->setContent(json_encode($output));
    $event->setResponse($response);
}

I tried to listen to the event COMPLETED, but does not make me change response!

Lughino
  • 4,060
  • 11
  • 31
  • 61

1 Answers1

1

You can grab form from $event object with $event->getForm() in PROFILE_EDIT_SUCCESS event.

in FOS\UserBundle\Controller\ProfileController:

$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);

To access email

$form = $event->getForm();
$email = $form['email']->getData();
Alexey B.
  • 11,965
  • 2
  • 49
  • 73
  • Really thank you very much! I was misled by the fact that if I passed a `$event->getForm()` or even `$event` I always returned an empty object! And this even now I don't know give me an explanation .. – Lughino Aug 02 '13 at 21:04
  • What exactly you do not understand? Event is just an simple object, which contains data from controller. You can modify this data, for example you can set response to it and controller will return this response. – Alexey B. Aug 03 '13 at 03:01