1

I am using FOSUserBundle. In my project, I created my own UserBundle and overrode the controller, the forms and the handlers. Now when a user tries to register with an existing email, the site crashes (email is unique for doctrine). It seems like there is no validation made. I thought there would be some validation as I have in my validation.yml:

YOP\UserBundle\Entity\User:
  constraints:
    - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email
  properties:
    email:
      - Email: ~

How come the validation isn't made on the email field? How can I make sure that my validation constraints are taken into account?

PS: the validation.yml file is not in my UserBundle, is that a problem?

EDIT:

the code of my UserBundle is available here I don't understand why there is no validation done anymore...

fkoessler
  • 6,932
  • 11
  • 60
  • 92

2 Answers2

6

Solved the issue by:

  • having the validation.yml file in the same bundle as the one containing my User entity, and pointing to my User Entity
  • adding the "Registration" validation group to my fields

validation.yml:

YOP\YourOwnPoetBundle\Entity\User:
  constraints:
    - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email
  properties:
    email:
      - Email: { groups: [Registration] }
    plainPassword:
      - MinLength: { limit: 5, message: "Your password must have at least {{ limit }} characters" }
    name:
      - NotBlank: { groups: [Registration] }
    familyName:
      - NotBlank: { groups: [Registration] }
    sex:
      - Choice: { choices: [1, 2], groups: [Registration] }
    birthdate:
      - NotNull: { groups: [Registration] }
    city:
      - NotBlank: { groups: [Registration] }
    howDidYouHear:
      - Choice: { choices: [1, 2, 3, 4, 5, 6, 7, 8], groups: [Registration] }
fkoessler
  • 6,932
  • 11
  • 60
  • 92
-1

validation.yml should be in your user bundle.
/app/config/config.yml should be updated as follow:

validation:      { enabled: true,  enable_annotations: false }
Florent
  • 12,310
  • 10
  • 49
  • 58
poojitha
  • 335
  • 1
  • 3
  • 12
  • thanks for your answer but this doesn't make any difference. How do I tell Symfony2 to use the validation.yml file? – fkoessler Sep 12 '12 at 07:32