gpt4 book ai didi

php - Symfony pre_submit 更改字段顺序

转载 作者:可可西里 更新时间:2023-10-31 23:37:28 24 4
gpt4 key购买 nike

给定以下表单类型,我如何在提交前呈现我的第二个字段?我尝试使用 $form->remove 但我总是会收到此错误:

Warning: Illegal offset type in isset or empty

不太确定如何解决这个问题。

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

])
->addEventListener(
FormEvents::PRE_SUBMIT,
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);
},
]);
}
);
}

最佳答案

我使用的解决方案是从类类型中删除提交按钮,然后手动将其添加到模板中,然后在提交按钮前使用 {{ form_rest(form) }},它会正常显示。

关于php - Symfony pre_submit 更改字段顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39965267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com