public function postFormPostAction(Request $request, $id)
    {
        /** @var Form $form */
        $form = $this->get('opifer.form.form_manager')->getRepository()->find($id);

        if (!$form) {
            throw $this->createNotFoundException('The form could not be found');
        }

        $data = json_decode($request->getContent(), true);

        $token = $data['_token'];
        if ($this->isCsrfTokenValid($form->getName(), $token)) {
            throw new InvalidCsrfTokenException();
        }

        // Remove the token from the data array, since it's not part of the form.
        unset($data['_token']);
        // We're stuck with a legacy form structure here, which we'd like to hide on the API.
        $data = ['valueset' => ['namedvalues' => $data]];

        /** @var Post $post */
        $post = $this->get('opifer.eav.eav_manager')->initializeEntity($form->getSchema());
        $post->setForm($form);

        $postForm = $this->createForm(PostType::class, $post, ['form_id' => $id, 'csrf_protection' => false]);
        $postForm->submit($data);

        if ($postForm->isSubmitted() && $postForm->isValid()) {
            $this->get('opifer.form.post_manager')->save($post);

            return new JsonResponse(['message' => 'Success'], 201);
        }

        return new JsonResponse([
            'errors' => (string) $postForm->getErrors()
        ], 400);
    }
public function postFormPostAction(Request $request, $id)
    {
        /** @var Form $form */
        $form = $this->get('opifer.form.form_manager')->getRepository()->find($id);

        if (!$form) {
            throw $this->createNotFoundException('The form could not be found');
        }

        $data = json_decode($request->getContent(), true);

        $token = $data['_token'];
        if ($this->isCsrfTokenValid($form->getName(), $token)) {
            throw new InvalidCsrfTokenException();
        }

        // Remove the token from the data array, since it's not part of the form.
        unset($data['_token']);
        // We're stuck with a legacy form structure here, which we'd like to hide on the API.
        $data = ['valueset' => ['namedvalues' => $data]];

        /** @var Post $post */
        $post = $this->get('opifer.eav.eav_manager')->initializeEntity($form->getSchema());
        $post->setForm($form);

        $postForm = $this->createForm(PostType::class, $post, ['form_id' => $id, 'csrf_protection' => false]);
        $postForm->submit($data);

        if ($postForm->isSubmitted() && $postForm->isValid()) {
            $this->get('opifer.form.post_manager')->save($post);

            return new JsonResponse(['message' => 'Success'], 201);
        }

        return new JsonResponse([
            'errors' => (string) $postForm->getErrors()
        ], 400);
    }
public function postFormPostAction ( Request $ request , $ id ) { /** @var Form $form */ $ form = $ this -> get ( 'opifer.form.form_manager' ) -> getRepository ( ) -> find ( $ id ) ; if ( ! $ form ) { throw $ this -> createNotFoundException ( 'The form could not be found' ) ; } $ data = json_decode ( $ request -> getContent ( ) , true ) ; $ token = $ data [ '_token' ] ; if ( $ this -> isCsrfTokenValid ( $ form -> getName ( ) , $ token ) ) { throw new InvalidCsrfTokenException ( ) ; } // Remove the token from the data array, since it's not part of the form. unset ( $ data [ '_token' ] ) ; // We're stuck with a legacy form structure here, which we'd like to hide on the API. $ data = [ 'valueset' => [ 'namedvalues' => $ data ] ] ; /** @var Post $post */ $ post = $ this -> get ( 'opifer.eav.eav_manager' ) -> initializeEntity ( $ form -> getSchema ( ) ) ; $ post -> setForm ( $ form ) ; $ postForm = $ this -> createForm ( PostType :: class , $ post , [ 'form_id' => $ id , 'csrf_protection' => false ] ) ; $ postForm -> submit ( $ data ) ; if ( $ postForm -> isSubmitted ( ) && $ postForm -> isValid ( ) ) { $ this -> get ( 'opifer.form.post_manager' ) -> save ( $ post ) ; return new JsonResponse ( [ 'message' => 'Success' ] , 201 ) ; } return new JsonResponse ( [ 'errors' => ( string ) $ postForm -> getErrors ( ) ] , 400 ) ; }
Handle the creation of a form post

@param Request $request
@param         $id

@return JsonResponse
Handle the creation of a form post