Reputation: 606
I am trying to customize form rendering in Symfony (http://symfony.com/doc/current/cookbook/form/form_customization.html). I manage to customize the "text" widgets but fail to customize the "submit" widget. I have been debugging this issue in numerous ways and came out to the following (more simple) roadblock:
My controller is very standard and looks like this:
$user = new user();
$form = $this->createFormBuilder($user)
->add('name','text')
//other text items...
->add('save','submit', array('label'=> 'Signup'))
$form->handleRequest($request);
if($form->is Valid()) {
//render the template...
}
Now, if I render the form in TWIG with
{{ form(form) }}
Everything works perfectly (the form gets submitted). But if I change this into:
{{ form_widget(form) }}
The "submit" button does not submit anything (which I guess means that either the button does not trigger anything or my form somehow would not be valid anymore).
Symfony documentation http://symfony.com/doc/current/cookbook/form/form_customization.html seems to state that those two should render the form similarly. Could anyone give some guidance on where this issue could be coming from? Ultimately, I get the same issue when I try to use {{ form_widget(form.save) }} to customize the "submit" button. Thanks.
Upvotes: 2
Views: 3424
Reputation: 595
The Symfony Best Practices book say "Best Practice: Add buttons in the templates, not in the form classes or the controllers."
Upvotes: 1