[英]Retrieve unmapped data from eventlistener in symfony form
I am currently creating a form that is supposed to retrieve the unmapped data to treat them before they are added to the database.我目前正在创建一个表单,该表单应该检索未映射的数据以在将它们添加到数据库之前对其进行处理。 How can I retrieve the unmapped data in the eventlistener?
如何在事件监听器中检索未映射的数据? Here is my formtype code:
这是我的表单类型代码:
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('currentState', ChoiceType::class, [
'choices' => [
'Disponible' => 1,
'Hors service' => 2,
'Réservé' => 3
],
])
[...
->add('combination_reference', TextType::class, [
'label'=>'Référence de la déclinaison',
'mapped'=>false,
'attr'=>[
'class'=>'form-control mb-2',
'placeholder'=>'Référence de la déclinaison'
]
])
->addEventListener(FormEvents::SUBMIT, function(FormEvent $formEvent){
[retrieve unmapped data (combination_reference) here]
})
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => PhysicalProduct::class,
"allow_extra_fields" => true
]);
}
You can access underlying unmapped data as follows您可以按如下方式访问底层未映射的数据
$form = $formEvent->getForm();
$combinationReference = $form->get('combination_reference')->getData();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.