L.S L.S - 1 year ago 214
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);

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download