Reputation: 4118
I'm trying to validate fields fosuserbundle in the controller. I'm passing the values from the request without using the form (I'm using the jquery plugin x-editable). So far I have tried this way but it saves me the email even if it is invalid or empty:
$userId = $request->get('pk');
$value = $request->get('value');
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('AcmeUserBundle:User')->find($userId);
if (!$user) {
throw $this->createNotFoundException('Unable to find Products entity.');
}
$user->setEmail($value);
$validator = $this->container->get('validator');
$errors = $validator->validate($user, array('profile'));
if (count($errors) > 0) {
return new Response(print_r($errors, true), 400);
}
$this->container->get('fos_user.user_manager')->updateUser($user);
return new Response('', 200);
Where am I doing wrong?
Upvotes: 2
Views: 1130
Reputation: 52483
FOSUserBundle uses "Profile" as validation group and not lowercase "profile".
Have a look at the validation configuration here and here.
Upvotes: 4