Skip to content
Advertisement

How to add options to a Symfony Form field?

I am rather new to PHP & Symfony, and am struggling with the form options:

I have the following, simple code:

JavaScript

I get an error because the format is not an option of TextType, but I cannot find a way to add my own options (But I know this is possible, from the others posts I read)

I have read a lot of other posts with similar issues, but cannot grasp how to do this (I tried the setDefaults options, but it didn’t lead me anywhere)

Advertisement

Answer

What you need is to create a new custom extension which extends the TextType like this for example:

JavaScript

Read more here: https://symfony.com/doc/current/form/create_form_type_extension.html

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement