Relative Content

Tag Archive for symfonysymfony-forms

Symfony form: Size not detected on svg image

I have a symfony form, where i upload images. Allowed types are jpeg and svg. When i added validation for maxWidth and maxHeight on jpeg works correctly, but on svg I get form error The size of the image could not be detected. (https://symfony.com/doc/5.x/reference/constraints/Image.html#sizenotdetectedmessage). I tried with many svg images and still the same error. Without the validation, they are uploading and rendered correctly on the template, so the images are not broken. What can i do to validate the width and height of the svg image? Here is the code of the form:

How to add dynamic fields to a Symfony form

I have a Symfony 7 form where I have a button called addOption. When clicked, I want to create two input fields to the form. Users can add and delete multiple fields. I have looked into the FormEvents but doesn’t seem to work.
Code is pretty much the standard form. I have created a QuestionType extending AbstractType and a model with the same fields.
I think there will be some javascript involved but I just can’t figure out the whole flow.