Tutorial by Examples

A form gives the user a way to change data in your application, in a structured way. To mutate a simple array of data, we create a form using a form builder: use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\F...
A custom form type is a class which defines a reusable form component. Custom form components can be nested to create complicated forms. Instead of creating a form in the controller using a form builder, you can use your own type to make the code more readable, reusable and maintanable. Create a c...
When rendering a form 'by hand', it can be useful to know if there are fields left to render or not. The function isRendered() from the FormView class returns true if there are still fields left to be rendered to the template. This snippet prints <h3>Extra fields</h3> if there are fiel...
In this example, I created a form which is used to register a new user. In the options passed to the form, I give the different roles a user can have. Creating a reusable class for my form with configured data class and an extra option that fills the choice field to pick a userrole: class UserType...
To be able do deal with form events, it's important to attach the request, that is send to a controller action after submitting a form, to the form created in that action. public function registerAction(Request $request) { $data = new ExampleObject(); $form = $this->createForm(Example...

Page 1 of 1