G
G
gitdev2021-01-28 09:29:03
symfony
gitdev, 2021-01-28 09:29:03

Creating a form in one place - processing in another. Is this correct in Symfony?

Roughly speaking - if I create a form and display it on the front, and behind

$propositionChat = $this->propositionChatService->createEntity();

        $form = $this->createForm(PropositionChatType::class, $propositionChat);

//эту часть обработки вынесу в другую часть проекта в API и буду отправлять запросы с помощью AJAX.
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $this->propositionChatService->createMessage($propositionChat, $proposition, $this->getUser());
        }


Is this correct or is it better to use another option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-01-28
@gitdev

Forms are needed where a person enters data through the UI. And in AJAX (aka API), the data arrives not in the form, but in the usual POST request, which is processed. And if necessary, it is validated using the .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question