最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Symfony Getting Error 422 Unprocessable Content in console - Stack Overflow

programmeradmin3浏览0评论

I am creating a form in symfony + turbo however when an error occurs in the form it returns status 422 which is Unprocessable Content.

There is nothing wrong with that however in the console it then gives me error 422 which stops my JS. In a way the form is dependent on JS - how to deal with it?

#[Route('/', name: 'overview')]
    public function app_panel_keys_overview(Request $request): Response  
    {
        $newKeyForm = $this->createForm(NewPublicKeyType::class);
        $newKeyForm->handleRequest($request);

        if ($newKeyForm->isSubmitted() && $newKeyForm->isValid()) {
            $keyType = $newKeyForm->get('keyType')->getData();
            $name = $newKeyForm->get('name')->getData();
            $description = $newKeyForm->get('description')->getData();
            $allowedIpAddresses = $newKeyForm->get('allowedIpAddresses')->getData();

            $this->tokenService->createNewPublicKey($this->getUser(), $keyType, $name, $allowedIpAddresses, $description);
        }

        if ($newKeyForm->isSubmitted() && !$newKeyForm->isValid()) {
            $request->setRequestFormat(TurboBundle::STREAM_FORMAT);
            return $this->renderBlock('panel/keys/overview.html.twig', 'form', ['newKeyForm' => $newKeyForm]);
        }
        
        return $this->render('panel/keys/overview.html.twig', [
            'newKeyForm' => $newKeyForm
        ]);
    }
<twig:Modal id="addNewKey" placement="right" toggle="false" title="" form="true" description="">
        <turbo-frame id="form_newKey">
            {{ form(newKeyForm) }}
        </turbo-frame>
    </twig:Modal>

{% block form %}
    <turbo-stream action="update" targets="#form_newKey">
        <template>
            {{ form(newKeyForm) }}
        </template>
    </turbo-stream>
{% endblock %}

I would like to get rid of 422 status code or get my js work after 422.

发布评论

评论列表(0)

  1. 暂无评论