validating fosuserbundle registration form

前端 未结 2 1187
面向向阳花
面向向阳花 2020-12-20 06:35

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 exist

相关标签:
2条回答
  • 2020-12-20 06:57

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

    validation:      { enabled: true,  enable_annotations: false }
    
    0 讨论(0)
  • 2020-12-20 07:01

    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] }
    
    0 讨论(0)
提交回复
热议问题