I'm not sure if I can use symfony collection type to achieve below form. PS: the list of social media channels is coming from yaml config as array. So for each channel I have to call the form type class and only have 1 submit button.
<form action="...">
Facebook:
- Now (checkbox)
- later (checkbox)
- <hidden input field value="facebook">
Instagram:
- Now
- later
- <hidden field value="instagram">
Twitter:
- Now
- later
- <hidden field value="twitter">
- submit
</form>
This is what I have right now in twig:
{% for channel in channels %}
{{ form_widget(form.channel, {'attr': {'value': channel }}) }}
{{ form_widget(form) }}
{% endfor %}
of course it won't work because the same field will be rendered several times and it will break on validation.
The build method still the basic example on how using ChoiceType:
$builder->add('options', ChoiceType::class, [
'choices' => [
'Not yet' => null,
'Now' => false,
'Draft' => false,
'later' => false
],
'expanded' => true
])
->add('channel', HiddenType::class)
So, how to render the same widget multiple times in Symfony form?