dongxin1999 2019-02-14 08:13
浏览 39

fosuserBundle - 表单寄存器中的显示错误

I try override register Action controller but error form (for example duplicate email is not display and i receive error 500 in action with this error symfony:

enter image description here

code controller:

public function new(Request $request){
    $user = new Client();
    $user->setEnabled(true);

    $event = new GetResponseUserEvent($user, $request);
    $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);

    if (null !== $event->getResponse()) {
      return $event->getResponse();
    }

    $form = $this->formFactory->createForm();
    $form->setData($user);
    $form->handleRequest($request);

    if ($form->isSubmitted()) {

      if ($form->isValid()) {
        $event = new FormEvent($form, $request);
        $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);

        $url = $this->generateUrl('fos_user_registration_confirmed');
        $response = new RedirectResponse($url);

        $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

        return $response;
      }

      $event = new FormEvent($form, $request);
      $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);
      if (null !== $response = $event->getResponse()) {
        return $response;
      }
    }

    return [
      'form' => $form->createView()
    ];
  }

code view:

{% trans_default_domain 'FOSUserBundle' %}
        <div class="justify-content-center row">
            <div class="col-md-8">
                {{ form_start(form, {'method': 'post', 'action': path('new_custom'), 'attr': {'class': 'fos_user_registration_register'}, 'attr':{'id': 'regForm'}}) }}

                        <div class="form-group">
                                {{ form_widget(form.email,{ 'attr': {'class': 'form-control','placeholder': 'Email'}}) }}
                                {{ form_errors(form.email) }}
                        </div>
                        <div class="form-group">
                                {{ form_widget(form.plainPassword.first,{ 'attr': {'class':'form-control' ,'placeholder': 'Password'} }) }}
                                {{ form_errors(form.plainPassword.first) }}
                        </div>
                            <div class="form-group">
                                {{ form_widget(form.plainPassword.second,{ 'attr': {'class':'form-control' ,'placeholder': 'Repeat your password'} }) }}
                                {{ form_errors(form.plainPassword.second) }}
                            </div>
                        <div class="form-group float-right" style="margin-top: 2%">
                                <input type="submit" class="submitRegister btn btn-primary" value="{{ 'registration.submit'|trans }}" />
                         </div>

                <div class="form-group float-left">
                    <a class="loginInRegister nav-link" data-toggle="modal" data-target="#modalLogin">
                        <input type="submit" class="btn btn-primary" value="Login" />
                    </a>
                </div>

                {{ form_end(form) }}
             </div>
        </div>
        <script src="{{ asset('js/main.js') }}"></script>

how to display error in form and not have error symfony with status 500 and in router fosuserbundle for default work but when i override register controller i have this error :(

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度