symfony form isvalid eqauls false but has no error

use*_*250 2 php forms doctrine symfony

I'm working on a symfony project which is already live and use doctrine. The problem I describe below is new and I'm certain it was caused by me but I can not confirm this as I'm unsure how to debug.

I have a simple form (it submits two fields) and I can see both these values have been submitted correctly by dumping the following:

$form->handleRequest($request);
Run Code Online (Sandbox Code Playgroud)

The problem is that although I can see the submitted values, the form does not pass validation:

if ($form->isValid() === false)
Run Code Online (Sandbox Code Playgroud)

This used to pass validation, perhaps 4 weeks ago so its something I've done recently.

I have dumped $form->getErrors(true); to see if I can find the error but it returns this:

RenderController.php on line 20:
FormErrorIterator {#685 ?
 -form: Form {#691 ?}
 -errors: []
}
Run Code Online (Sandbox Code Playgroud)

So unless I'm mistaken, no errors are found here as the errors is empty.

I have read that $form->isValid() checks the data model, i.e. the underlying entity objects.

I have recently made changes to an entity. I did this by first adding a field to the database and then going into the entity class to updating it manually.

Is it possible that I have done something wrong when adding the new field? What confuses me is that are other forms which use the new field and I have not experienced any issues with.

Should I have not done this manually? How do I debug the form further?

Ema*_*ter 5

这可能是由 symfony 中的验证工作方式引起的。正如您所写的那样, $form->isValid() 实际上并没有验证表单本身。而是验证底层实体。

现在到了棘手的部分:不仅表单中存在的字段经过验证,而且实体的每个字段都经过验证。如果您的表单仅代表您的实体的一部分,则会发生所描述的效果。可能添加的字段之一具有 NotBlank 断言(或类似),但不存在于您的表单中。对于新实体,这将始终失败。并且由于该字段不存在于表单中,因此表单中也没有错误。

要解决此问题,请扩展您的表单,从新字段中删除断言或查看验证组