Answer the question
In order to leave comments, you need to log in
How to save/get the value between form submission attempts?
Symfony project in which the Sylius plugin is used
There is a standard entity Customer, the creation of which needs to be redefined depending on what type of this customer
If isCompany - additional fields are added The
resource controller of the vendor /admin/customers/new is
used I added a qveri parameter and try to process this matter in CustomerProfileTypeExtension
Something like /admin/customers/new?isCompany=1
In the form builder I add an event listener and use the isCompany value to manage the form
The problem is that when I submit the form, it redirects to the standard resource url /admin/customers/new
And my get parameter is lost and I can't properly validate the form
Nagovnokodil such a method that checks
private function resolveCustomerType(FormEvent $event): ?bool {
$customerType = $_GET['isCompany'] ?? null;
$referer = $_SERVER['HTTP_REFERER'] ?? null;
if ($customerType !== null) {
return (bool) $_GET['isCompany'];
}
if ($referer !== null) {
$query = parse_url($referer, PHP_URL_QUERY);
if ($query) {
return (bool) explode('=', $query)[1];
}
}
// $form->get('isCompany')->getData() === NULL
// $event->getData()->getIsCompany() === NULL
// здесь никак не получается достать раннее установленное значение isCompany
return null;
}
sylius_admin_customer_create.company:
path: /admin/customers/new/company
methods: [GET, POST]
defaults:
_controller: sylius.controller.customer:createAction
_sylius:
section: admin
redirect: sylius_admin_customer_index
template: "@SyliusAdmin/Crud/create.html.twig"
form: App\Form\Type\CustomerCompanyType
vars:
templates:
form: "@SyliusAdmin/Customer/_form.company.html.twig"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question