M
M
multifinger2012-11-14 18:43:56
symfony
multifinger, 2012-11-14 18:43:56

How to build a non-trivial Symfony2 Form Validator?

After switching to sf2, everything turned upside down. I just can't find an answer to this case:
I have a Doctrine Entity and I have a form to save this Entity. Let's say it's Recipe.
Recipe has a name field and an image field, and image is an id pointing to another Entity - a picture, information about which is stored in the database (its own storage of media files is implemented), i.e. in the Recipe->image class, this is an Image instance - another Entity that implements a one-to-many relationship.
I created a separate FormType (field) for image based on the hidden field, the image is loaded by Ajax, and the id of the image in the storage is substituted in the hidden.
The question is how do I correctly create a validator, because I unbind the image field from the object. because it's an integer value, and the form is waiting for an ImageEntity object.
I try different options - it doesn’t work, and manually checking all the fields before saving the form by creating a validator for each input is completely ugly. I want to do something the right way, but it's not clear how.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
multifinger, 2012-11-14
@multifinger

Apparently the solution to my problem is How to use Data Transformers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question