Symfony

Symfony Forms

FormType, form builder, validation, CSRF, file upload, custom form types, data transformers

22 interview questionsยท
Junior
1

Which base class should be extended to create a custom form type in Symfony?

Answer

AbstractType is the base class that all Symfony form types must extend. It provides the buildForm() method to configure fields and configureOptions() to define form options like data_class. This object-oriented approach allows forms to be reused across multiple controllers.

2

Which method should be used in a FormType to add fields to the form?

Answer

The buildForm() method receives a FormBuilderInterface that allows adding fields via the add() method. This method is called automatically when the form is created and allows defining all fields with their respective types and options.

3

How to handle form submission in a Symfony controller?

Answer

The handleRequest() method reads data from the HTTP request and binds it to the form. Then, isSubmitted() checks if the form was submitted and isValid() verifies that data meets validation constraints. This pattern is standard for all Symfony forms.

4

Which option links a form to an entity class in configureOptions()?

5

How to retrieve submitted data from a validated form?

+19 interview questions

Master Symfony for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free