Freiyer
Freiyer

Reputation: 149

Calling an action controller on submit button

Is it possible to call a controller action on a form submit button, what is the syntax in twig Please?

Upvotes: 1

Views: 5156

Answers (2)

RL89
RL89

Reputation: 1916

In case of Asp.net MVC

 @using (Html.BeginForm("ActionName", "ContorllerName", FormMethod.Post}))
  {
      <p>
        <input type="submit" value="Submit" />
    </p>

   }

This is how you can call a Controller action on submit button

Upvotes: -3

Bgi
Bgi

Reputation: 2494

Yes it is :

{# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #}
<form action="{{ path('task_new') }}" method="post" {{ form_enctype(form) }}>
    {{ form_widget(form) }}

    <input type="submit" />
</form>

You must set the action="" attribute of the form tag by using the twig helper path. to your correct route.

More information in Symfony2's documentation about forms.

Upvotes: 5

Related Questions