Question

I want to use data from request header (http headers) as hidden fields in my form.
The easiest way is to add a new hidden field via the form builder and set the data.

But I want to use it for more than one form so an own type would be good.
Setting the data via the parameters array or passing them via constructor should fit this requirement.

This would be "a lot of" copy/paste-work. I don't want this, I search for a nice way. A little bit closer to the framework.
I have read that I can use closures for the options with the OptionsResolverInterface.

Is there any possibility to use them for this requirement?
Or is the only way to pass the Request object via parameters array/constructor into the type?

Perhaps there is a possibility to use an event listener or anything like that.

Thanks in advance for any hints.

Était-ce utile?

La solution

You can create trait or abstract class for your form types with function which add fields to your builder

something like that

function addFields($builder)
{
    $builder->add('fildName1', 'hidden');
    $builder->add('fildName2', 'hidden');
    .....
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top