Linked Questions

Popular Questions

Form with CSRF token only

Asked by At

I have a form which require only the CRSF token. Other parameters are provided from the URL itself, or are default value.

/**
 * @Route("/projets/projet-{projetId}/accessoires/accessoire-{accessoireId}/new/", name="projetaccessoire_new")
 * @ParamConverter("projet", options={"mapping"={"projetId"="id"}})
 * @ParamConverter("accessoire", options={"mapping"={"accessoireId"="id"}})
 * @Method({"POST")
 *
 * @param Request $request
 * @param Projet $projet
 * @param Accessoire $accessoire
 * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
 */
public function newAction(Request $request, Projet $projet, Accessoire $accessoire) {
    $projetAccessoire=new ProjetAccessoire();
    $form=$this->createForm(ProjetAccessoireType::class, $projetAccessoire, array(
        'action'=>$this->generateUrl('projetaccessoire_new', array('projetId'=>$projet->getId(), 'accessoireId'=>$accessoire->getId())),
        'method'=>'POST',
    ));
    $form->handleRequest($request);

    if($form->isSubmitted() && $form->isValid()) {
        $projetAccessoire->setProjets($projet)
                         ->setAccessoires($accessoire)
                         ->setPosX(0)
                         ->setPosY(0)
                         ->setRotZ(0);

        $em=$this->getDoctrine()->getManager();
        $em->persist($projetAccessoire);
        $em->flush();

        return $this->json(array(
            'message_info'=>array(
                array(
                    'message'=>'Projet enregistré',
                    'type'=>'success',
                ),
            ),
        ));
    }

    return $this->render($this->path.'projetaccessoire_new.html.twig', array(
        'projet'=>$projet,
        'accessoire'=>$accessoire,
        'projetAccessoire'=>$projetAccessoire,
        'form'=>$form->createView(),
    ));
}

The thing is, what should I put in ProjetAccessoireType to have only the CRSF token.
Can someone provide me with an code example?

Related Questions