Getting multiple fields, in event listener
up vote
0
down vote
favorite
For example if we got a POST_SUBMIT event listener,
$builder->get('client')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event)
{
$form = $event->getForm();
$data = $form->getData();
if($data) {
$shippings = $form->getData()->getClientsShippings()->getValues();
$form->getParent()->add('shipping', EntityType::class, [
'class' => ClientsShippings::class,
'placeholder' => 'Wybierz adres dostawy',
'choices' => $shippings,
'attr' => [
'class' => 'chosen-select',
],
'choice_label' => function ($shipping) {
return "".$shipping->getJson()['clients_shippings']['name']." | ".$shipping->getJson()['clients_shippings']['ulica']." | ".$shipping->getJson()['clients_shippings']['miejscowosc']."";
}
]);
}
});
and thats gives possibility to manage data but only form 'client' field. How i can add another fields to this eventlistener.
Why ?
Becouse i wanna create eventListener on delivery methods filed, and if i handle this event i wanna take CollectionType of products field and check how many products there is and do the math, how much delivery will coast.
So i need to get:
CollectionType field named 'order_products',
ChoiceType field names 'order_payment' -> get price table (is entity),
do the math,
and add new field TextType with value comes from maths.
Any idea how i can pass more than one field to EventListener or how to get this done ?
php forms symfony4
add a comment |
up vote
0
down vote
favorite
For example if we got a POST_SUBMIT event listener,
$builder->get('client')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event)
{
$form = $event->getForm();
$data = $form->getData();
if($data) {
$shippings = $form->getData()->getClientsShippings()->getValues();
$form->getParent()->add('shipping', EntityType::class, [
'class' => ClientsShippings::class,
'placeholder' => 'Wybierz adres dostawy',
'choices' => $shippings,
'attr' => [
'class' => 'chosen-select',
],
'choice_label' => function ($shipping) {
return "".$shipping->getJson()['clients_shippings']['name']." | ".$shipping->getJson()['clients_shippings']['ulica']." | ".$shipping->getJson()['clients_shippings']['miejscowosc']."";
}
]);
}
});
and thats gives possibility to manage data but only form 'client' field. How i can add another fields to this eventlistener.
Why ?
Becouse i wanna create eventListener on delivery methods filed, and if i handle this event i wanna take CollectionType of products field and check how many products there is and do the math, how much delivery will coast.
So i need to get:
CollectionType field named 'order_products',
ChoiceType field names 'order_payment' -> get price table (is entity),
do the math,
and add new field TextType with value comes from maths.
Any idea how i can pass more than one field to EventListener or how to get this done ?
php forms symfony4
ok all what i need is just change to this:$builder->addEventListener(
thx anyway
– flow
Nov 11 at 12:59
but ther problem is now that:You cannot add children to a submitted form
any idea how to solve this all ?
– flow
Nov 11 at 13:08
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
For example if we got a POST_SUBMIT event listener,
$builder->get('client')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event)
{
$form = $event->getForm();
$data = $form->getData();
if($data) {
$shippings = $form->getData()->getClientsShippings()->getValues();
$form->getParent()->add('shipping', EntityType::class, [
'class' => ClientsShippings::class,
'placeholder' => 'Wybierz adres dostawy',
'choices' => $shippings,
'attr' => [
'class' => 'chosen-select',
],
'choice_label' => function ($shipping) {
return "".$shipping->getJson()['clients_shippings']['name']." | ".$shipping->getJson()['clients_shippings']['ulica']." | ".$shipping->getJson()['clients_shippings']['miejscowosc']."";
}
]);
}
});
and thats gives possibility to manage data but only form 'client' field. How i can add another fields to this eventlistener.
Why ?
Becouse i wanna create eventListener on delivery methods filed, and if i handle this event i wanna take CollectionType of products field and check how many products there is and do the math, how much delivery will coast.
So i need to get:
CollectionType field named 'order_products',
ChoiceType field names 'order_payment' -> get price table (is entity),
do the math,
and add new field TextType with value comes from maths.
Any idea how i can pass more than one field to EventListener or how to get this done ?
php forms symfony4
For example if we got a POST_SUBMIT event listener,
$builder->get('client')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event)
{
$form = $event->getForm();
$data = $form->getData();
if($data) {
$shippings = $form->getData()->getClientsShippings()->getValues();
$form->getParent()->add('shipping', EntityType::class, [
'class' => ClientsShippings::class,
'placeholder' => 'Wybierz adres dostawy',
'choices' => $shippings,
'attr' => [
'class' => 'chosen-select',
],
'choice_label' => function ($shipping) {
return "".$shipping->getJson()['clients_shippings']['name']." | ".$shipping->getJson()['clients_shippings']['ulica']." | ".$shipping->getJson()['clients_shippings']['miejscowosc']."";
}
]);
}
});
and thats gives possibility to manage data but only form 'client' field. How i can add another fields to this eventlistener.
Why ?
Becouse i wanna create eventListener on delivery methods filed, and if i handle this event i wanna take CollectionType of products field and check how many products there is and do the math, how much delivery will coast.
So i need to get:
CollectionType field named 'order_products',
ChoiceType field names 'order_payment' -> get price table (is entity),
do the math,
and add new field TextType with value comes from maths.
Any idea how i can pass more than one field to EventListener or how to get this done ?
php forms symfony4
php forms symfony4
asked Nov 11 at 12:24
flow
517
517
ok all what i need is just change to this:$builder->addEventListener(
thx anyway
– flow
Nov 11 at 12:59
but ther problem is now that:You cannot add children to a submitted form
any idea how to solve this all ?
– flow
Nov 11 at 13:08
add a comment |
ok all what i need is just change to this:$builder->addEventListener(
thx anyway
– flow
Nov 11 at 12:59
but ther problem is now that:You cannot add children to a submitted form
any idea how to solve this all ?
– flow
Nov 11 at 13:08
ok all what i need is just change to this:
$builder->addEventListener(
thx anyway– flow
Nov 11 at 12:59
ok all what i need is just change to this:
$builder->addEventListener(
thx anyway– flow
Nov 11 at 12:59
but ther problem is now that:
You cannot add children to a submitted form
any idea how to solve this all ?– flow
Nov 11 at 13:08
but ther problem is now that:
You cannot add children to a submitted form
any idea how to solve this all ?– flow
Nov 11 at 13:08
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248729%2fgetting-multiple-fields-in-event-listener%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
ok all what i need is just change to this:
$builder->addEventListener(
thx anyway– flow
Nov 11 at 12:59
but ther problem is now that:
You cannot add children to a submitted form
any idea how to solve this all ?– flow
Nov 11 at 13:08