Symfony2 : Two forms in a same page

前端 未结 7 776
感情败类
感情败类 2020-12-05 23:50

I\'ve got two forms in a same page.

My problem is when I tried to submit a form, it\'s like it tried to submit the second form below in the page as well.

As

7条回答
  •  攒了一身酷
    2020-12-06 00:35

    You have to treat the forms separately:

    if('POST' === $request->getMethod()) {
     
        if ($request->request->has('form1name')) {
            // handle the first form  
        }
    
        if ($request->request->has('form2name')) {
            // handle the second form  
        }
    }
    

    This is perfectly explained in Symfony2 Multiple Forms: Different From Embedded Forms (temporarily unavailable - see below)

    Update

    As the link provided above is temporarily unavailable, you can see an archive of that resource here.

提交回复
热议问题