I am searching for an easy way to add a bundle of fields to each form.
I have found a way to extend the AbstractType and use the buildForm
method to add more fields.
When creating the form I give the name of my new type (How to Create a Custom Form Field Type).
In my opinion it is an easy way, but it is restricted to one type per form.
Is there a better way to achieve anything like that?
I have read the cookbook of symfony, but I have only found stuff how to extend an existing form not how to create an own form "template" with my fields.
You can do this with the getParent() function.
Have you tried using inheritance?
This is really simple, first you have to define a form type:
Then you can
extend
this form type:The
BaseType
will display a name field and an add submit button. TheExtendType
will display a name field, an add submit button and a number field.