Symfony2 : Two forms in a same page

前端 未结 7 773
感情败类
感情败类 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:49

    This is how I handle them on my controller :

    return $this->render('SgaDemandeBundle:Demande:suivi_avancement.html.twig', 
                         array('form' => $form->createView(), 
                               ........
                               'update' => $formModification->createView()));
    

    This is the html for the second form :

    <div class="well">
        <form method="post">
            <div id="form">
                <div>
                    <button type="submit" id="form_modification"  
                    name="form[modification]">Modification done
                    </button>
                </div>
                <input type="hidden" id="form__token" name="form[_token]" 
                value="fFjgI4ecd1-W70ehmLHmGH7ZmNEHAMqXlY1WrPICtK4">
            </div>        
        </form>
    </div>
    

    This is my twig rendered :

    <div class="well">
        <form method="post" {{form_enctype(update)}} >
            {{ form_widget(update) }}
        </form>
    </div>
    
    <div class="well">
        <form method="post" action='' {{form_enctype(form)}} >
            {{ form_widget(form) }}
            <input type="submit" class="btn btn-primary"/>
        </form>
         <div class='errors'>
            {{ form_errors(form) }}
         </div>
    </div>
    

    I hope this will help you.

    0 讨论(0)
提交回复
热议问题