3

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.

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi thx for the answer, i was looking in that direction, just had problems with the multiple fields in one field type. in the end it seems like i was missing a DataTransformer to make it work. thx !
Thanks Roberto for pointing to the DateTimeType asn an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.