how to return json encoded form errors in symfony

前端 未结 6 2031
臣服心动
臣服心动 2020-12-08 03:22

I want to create a webservice to which I submit a form, and in case of errors, returns a JSON encoded list that tells me which field is wrong.

currently I only get a

6条回答
  •  情深已故
    2020-12-08 03:26

    This does the trick for me

     $errors = [];
     foreach ($form->getErrors(true, true) as $formError) {
        $errors[] = $formError->getMessage();
     }
    

提交回复
热议问题