Reputation: 7257
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...
Upvotes: 1
Views: 5755
Reputation: 7257
Solved the issue by:
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] }
Upvotes: 6
Reputation: 335
validation.yml
should be in your user bundle.
/app/config/config.yml
should be updated as follow:
validation: { enabled: true, enable_annotations: false }
Upvotes: -1