Symfony 2.8 - How to handle datatype of a column different in formBuilder and entity file

79 Views Asked by At

In the form builder I have added field with:

type : ChoiceType
multiple : true

In the entityfile that column is defined as:

Type : string

The same column in database table contains type text.

Now I want to insert values selected in form field as comma separated string.

But in below steps it is not allowing to submit the form and throwing error.

$form->handleRequest($request);

Here, the system is not setting any data of the field from $request to $form

$form->isValid()

So, this is not allowing to submit form and, also throws an error.

So, what I need to my data works in the correct way?

1

There are 1 best solutions below

2
Alexander Dimitrov On

You need to use a DataTransformer. This will allow you to transform the array from the form into a string. Check here