L.S L.S - 15 days ago 5x
PHP Question

Symfony pre_submit change field order

Given the following form type how can I render my second field before submit?
I tried with

but I would always get this error:

Warning: Illegal offset type in isset or empty

Not really sure how to fix this one.

* @param FormBuilderInterface $builder
* @param array $options
public function buildForm(FormBuilderInterface $builder, array $options)
->add('survey', EntityType::class, [
'class' => SurveyManager::class,
'attr' => [
'class' => 'field-change',
->add('submit', SubmitType::class, [

function (FormEvent $event) {
$form = $event->getForm();

$data = $event->getData();
$modifier = $data['survey'];
$form->add('headquarter', EntityType::class, [
'class' => HeadQuarterManager::class,
'query_builder' => function (HeadQuarterManagerRepository $er) use ($modifier) {
return $er->getHeadquarter($modifier);


Symfony's Form component do not support rearranging form's fields. They talked about this feature on issue #5827 and #11241.

You could try to remove field submit in EventListener, then add headquerter and also submit (yes, once again). But I am not sure this will be work.

Another solution is install IvoryOrderedFormBundle. It adds new option in form fields: position.