formssymfony-2.1custom-field-type

Symfony Form Type with multiple input fields


With Symfony 2.1, how can I create a form type with multiple input fields in it? So in the form builder I want to add a custom form type :

$builder->add('test','my_fieldtype')

Then if I do this in the template :

{{ form_row(form.test) }}

I want it to display a row that has a label and 2 or 3 input fields. Something like the date type I suppose.


Solution

  • You will need to create a custom field type. The best way to achieve it is to look at the code of the DateTimeType.

    Remember to create as well the appropriate Twig form template.