如何使用symfony2表单按钮调用控制器函数

Usually i declare my buttons in symfony2 like this:

<a href="{{ path('delete_route_name', {'id': entity.id }) }}">Delete</a>

but in this case i have to use the following statement:

$form->add('submit', 'submit', array('label' => 'Save Changes', 'attr' => array('style' => 'position: relative; left:33%')));

because this button is just in some cases (within the form) necessery.

As well i want call a function in a controller with this button. How i can add a controller path to this button?

of course i can work with JavaScript, but im looking for a Solution without some JavaScript.

Thanks for the feedbacks.

You must add the path to the form action as an form config parameter.

If you want to add a <a href=""></a> link/button to the form, take a look to the docs to learn how to render Symfony forms widget by widget (or row by row). Then, you can add the link/button above the form_end(form) function in your template.

You can use multiple submit buttons and in your code do something like this:

        if ($form->isSubmitted() && $form->isValid()) {

            //button 1
            if ($form->get('submit_1')->isClicked()) {
                return $this->myOtherControllerAction($request, $form);
                //or $this->forward   see https://symfony.com/doc/current/controller/forwarding.html
            }
        }