Reputation: 583
I have a dropdown list that should be filled from an excel file column for now I am filling the list directly:
Formbuilder:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('Author', ChoiceType::class, array(
'choices' => array(
'Author1' => 'Author1',
'Author2' => 'Author2',
'Author3' => 'Author3'
)))
;
}
twig
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
{{ form_widget(form.Author, {'attr': {'class' : 'form-control '}}) }}
</div>
is that doable from the form builder ?
Upvotes: 0
Views: 76
Reputation: 1082
Add it to your FormBuilder definitions as params like :
$data = $options['data'];
Pass it as 'choices' of your field
Then, pass data as params of formbuilder like ($data contains infos from phpExcel) :
$form = $this->createForm(YourType::class, $entity, ['data' => $data]);
Upvotes: 1