Tuesday 15 February 2011

php - Symfony2 FOSUserBundle extending registration form causes duplicate email to validate -


I have a custom registration form type that is defined as:

  .... public functions buildForm (FormBuilderInterface $ builder, array $ option) {Origin: buildForm ($ manufacturer, $ option); ('Username') - & gt; Remove ('first name') - & gt; Addition ('Last Name') - & gt; Add ('hei', 'entity', array ('class' = & gt;' Aqeamebibandal: higher educational institute ',' label '=> higher education institute')); } ....   

Custom Controller works equally in the ForcesBundle and also checks for a valid form

  ... Public Function Register Est Student Action (Request $ Request) {$ ** $ FormFiner \ FOS \ UserBundle \ Form \ Factory \ Factory Interfaces * / $ formfactor = $ this- & gt; Get ('ACM.USER_Formacator'); / $ @ $ User Manager \ FOS \ UserBundle \ Model \ UserManagerInterface * / $ userManager = $ this- & gt; Obtain ('fos_user.user_manager'); / ** @ War $ Sender \ Symfony \ Component \ Event Dispatcher \ EventDispatcherInterface * / $ dispatcher = $ this- & gt; Obtain ('event_dispatcher'); $ User = $ userManager- & gt; CreateUser (); $ User- & gt; SetEnabled (true); $ Sender- & gt; Sending (FOSUserEvents :: REGISTRATION_INITIALIZE, new UserEvent ($ user, $ request)); $ Form = $ formFactory- & gt; GetStudentRegistrationForm (); $ Form & gt; SetData ($ user); If ('POST' === $ request- & gt; getMethod ()) {$ form-> Tie ($ request); If ($ form-> isValid ()) {$ event = new FormEvent ($ form, $ request); $ Sender- & gt; Sending (FOSUserEvents :: REGISTRATION_SUCCESS, $ event); $ User- & gt; AddRole ('ROLE_STUDENT'); $ UserManager- & gt; UpdateUser ($ user); If (null === $ response = $ event-> getResponse ()) {$ url = $ this- & gt; Receive ('router') - & gt; Generate ('fos_user_registration_confirmed'); $ Response = new redirection response ($ url); } $ Sender- & gt; Remittance (FOSUserEvents :: Registration_ COMPLETED, New FilterUserResponseEvent ($ user, $ request, $ response)); $ Refund; }} $ $ Return - ('AcmeUserBundle: Registration: register_student.html.twig'), array ('form' = & gt; $ form-> createView ())); } ....   

When I try to register with an email address already in use then I get a theory exception to duplicate entry for a unique key on email Used to be.

I am seeing a form error in the normal registration form that the email address was already used. How can the form be a validator with a duplicate email address in my form but not in the original registration form?

AcmeBundle / resource / config

  Acme \ UserBundle \ Entity \ User: Barriers: - Fixed it by adding additional validation.yml for Symfony \ Bridge \ Doctrine \ Validator \ Constraints \ UniqueEntity. Field: Email, Message: "This email is already registered"} - Symphony \ Bridge \ Principle / Validator \ Barriers \ UniqueEntity: EmailCanual Properties: Email: - Email: ~ EmailSpeak: - Email: ~ plain password: - Length: Minimum: 7 minutes of message: "Your password must be at least {{limit}} character"    

No comments:

Post a Comment