public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // do nothing if it's not the master request
            return;
        }

        $request = $event->getRequest();

        if (!$request->isMethod('post')) {
            // do nothing if it's not a post request
            return;
        }

        try {
            /** @var FormInterface $form */
            $form = $this->formBuilder->buildByRequest($request);

            if (!$form || !$form->isSubmitted() || !$form->isValid()) {
                // do nothing when no form was found or not valid
                return;
            }
        } catch (\Exception $e) {
            // Catch all exception on build form by request
            return;
        }

        /** @var Dynamic $dynamic */
        $dynamic = $form->getData();
        $configuration = $this->formConfigurationFactory->buildByDynamic($dynamic);
        $dynamic->setLocale($request->getLocale()); // Need to be set to request locale for shadow pages, configuraiton will hold the original locale

        if ($this->formHandler->handle($form, $configuration)) {
            $serializedObject = $dynamic->getForm()->serializeForLocale($dynamic->getLocale(), $dynamic);
            $dynFormSavedEvent = new DynFormSavedEvent($serializedObject, $dynamic);
            $this->eventDispatcher->dispatch(DynFormSavedEvent::NAME, $dynFormSavedEvent);

            $response = new RedirectResponse('?send=true');
            $event->setResponse($response);
        }
    }
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // do nothing if it's not the master request
            return;
        }

        $request = $event->getRequest();

        if (!$request->isMethod('post')) {
            // do nothing if it's not a post request
            return;
        }

        try {
            /** @var FormInterface $form */
            $form = $this->formBuilder->buildByRequest($request);

            if (!$form || !$form->isSubmitted() || !$form->isValid()) {
                // do nothing when no form was found or not valid
                return;
            }
        } catch (\Exception $e) {
            // Catch all exception on build form by request
            return;
        }

        /** @var Dynamic $dynamic */
        $dynamic = $form->getData();
        $configuration = $this->formConfigurationFactory->buildByDynamic($dynamic);
        $dynamic->setLocale($request->getLocale()); // Need to be set to request locale for shadow pages, configuraiton will hold the original locale

        if ($this->formHandler->handle($form, $configuration)) {
            $serializedObject = $dynamic->getForm()->serializeForLocale($dynamic->getLocale(), $dynamic);
            $dynFormSavedEvent = new DynFormSavedEvent($serializedObject, $dynamic);
            $this->eventDispatcher->dispatch(DynFormSavedEvent::NAME, $dynFormSavedEvent);

            $response = new RedirectResponse('?send=true');
            $event->setResponse($response);
        }
    }
public function onKernelRequest ( GetResponseEvent $ event ) { if ( ! $ event -> isMasterRequest ( ) ) { // do nothing if it's not the master request return ; } $ request = $ event -> getRequest ( ) ; if ( ! $ request -> isMethod ( 'post' ) ) { // do nothing if it's not a post request return ; } try { /** @var FormInterface $form */ $ form = $ this -> formBuilder -> buildByRequest ( $ request ) ; if ( ! $ form || ! $ form -> isSubmitted ( ) || ! $ form -> isValid ( ) ) { // do nothing when no form was found or not valid return ; } } catch ( \ Exception $ e ) { // Catch all exception on build form by request return ; } /** @var Dynamic $dynamic */ $ dynamic = $ form -> getData ( ) ; $ configuration = $ this -> formConfigurationFactory -> buildByDynamic ( $ dynamic ) ; $ dynamic -> setLocale ( $ request -> getLocale ( ) ) ; // Need to be set to request locale for shadow pages, configuraiton will hold the original locale if ( $ this -> formHandler -> handle ( $ form , $ configuration ) ) { $ serializedObject = $ dynamic -> getForm ( ) -> serializeForLocale ( $ dynamic -> getLocale ( ) , $ dynamic ) ; $ dynFormSavedEvent = new DynFormSavedEvent ( $ serializedObject , $ dynamic ) ; $ this -> eventDispatcher -> dispatch ( DynFormSavedEvent :: NAME , $ dynFormSavedEvent ) ; $ response = new RedirectResponse ( '?send=true' ) ; $ event -> setResponse ( $ response ) ; } }
On Kernel request.

@param GetResponseEvent $event
On Kernel request .